File tree 2 files changed +22
-4
lines changed
2 files changed +22
-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 3
3
4
4
from crate import client
5
5
from crate .client .exceptions import ProgrammingError
6
+ from crate .client .result import BulkResponse
6
7
from crate .client .test_support import setUpCrateLayerBaseline , tearDownDropEntitiesBaseline
7
8
from crate .testing .settings import crate_host
8
9
@@ -68,3 +69,18 @@ def test_executemany_empty(self):
68
69
69
70
cursor .close ()
70
71
connection .close ()
72
+
73
+ @unittest .skipIf (sys .version_info < (3 , 8 ), "BulkResponse needs Python 3.8 or higher" )
74
+ def test_bulk_response_empty_records_or_results (self ):
75
+
76
+ with self .assertRaises (ValueError ) as cm :
77
+ BulkResponse (records = None , results = None )
78
+ self .assertEqual (
79
+ str (cm .exception ),
80
+ "Processing a bulk response without records is an invalid operation" )
81
+
82
+ with self .assertRaises (ValueError ) as cm :
83
+ BulkResponse (records = [], results = None )
84
+ self .assertEqual (
85
+ str (cm .exception ),
86
+ "Processing a bulk response without results is an invalid operation" )
You can’t perform that action at this time.
0 commit comments