File tree 2 files changed +24
-4
lines changed
2 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,12 @@ class BulkResponse:
20
20
21
21
def __init__ (
22
22
self ,
23
- records : t .Union [t .Iterable [t .Dict [str , t .Any ]], None ],
24
- results : t .Union [t .Iterable [BulkResultItem ], None ]):
23
+ records : t .List [t .Dict [str , t .Any ]],
24
+ results : t .List [BulkResultItem ]):
25
+ if records is None :
26
+ raise ValueError ("Processing a bulk response without records is an invalid operation" )
27
+ if results is None :
28
+ raise ValueError ("Processing a bulk response without results is an invalid operation" )
25
29
self .records = records
26
30
self .results = results
27
31
@@ -34,8 +38,6 @@ def failed_records(self) -> t.List[t.Dict[str, t.Any]]:
34
38
35
39
https://cratedb.com/docs/crate/reference/en/latest/interfaces/http.html#error-handling
36
40
"""
37
- if self .records is None or self .results is None :
38
- return []
39
41
errors : t .List [t .Dict [str , t .Any ]] = []
40
42
for record , status in zip (self .records , self .results ):
41
43
if status ["rowcount" ] == - 2 :
Original file line number Diff line number Diff line change @@ -68,3 +68,21 @@ def test_executemany_empty(self):
68
68
69
69
cursor .close ()
70
70
connection .close ()
71
+
72
+ @unittest .skipIf (sys .version_info < (3 , 8 ), "BulkResponse needs Python 3.8 or higher" )
73
+ def test_bulk_response_empty_records_or_results (self ):
74
+
75
+ # Import at runtime is on purpose, to permit skipping the test case.
76
+ from crate .client .result import BulkResponse
77
+
78
+ with self .assertRaises (ValueError ) as cm :
79
+ BulkResponse (records = None , results = None )
80
+ self .assertEqual (
81
+ str (cm .exception ),
82
+ "Processing a bulk response without records is an invalid operation" )
83
+
84
+ with self .assertRaises (ValueError ) as cm :
85
+ BulkResponse (records = [], results = None )
86
+ self .assertEqual (
87
+ str (cm .exception ),
88
+ "Processing a bulk response without results is an invalid operation" )
You can’t perform that action at this time.
0 commit comments