File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,12 @@ class BulkResponse:
2020
2121 def __init__ (
2222 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" )
2529 self .records = records
2630 self .results = results
2731
@@ -34,8 +38,6 @@ def failed_records(self) -> t.List[t.Dict[str, t.Any]]:
3438
3539 https://cratedb.com/docs/crate/reference/en/latest/interfaces/http.html#error-handling
3640 """
37- if self .records is None or self .results is None :
38- return []
3941 errors : t .List [t .Dict [str , t .Any ]] = []
4042 for record , status in zip (self .records , self .results ):
4143 if status ["rowcount" ] == - 2 :
Original file line number Diff line number Diff line change 33
44from crate import client
55from crate .client .exceptions import ProgrammingError
6+ from crate .client .result import BulkResponse
67from crate .client .test_support import setUpCrateLayerBaseline , tearDownDropEntitiesBaseline
78from crate .testing .settings import crate_host
89
@@ -68,3 +69,18 @@ def test_executemany_empty(self):
6869
6970 cursor .close ()
7071 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