Add BulkResponse wrapper for improved decoding of HTTP bulk responses#649
Add BulkResponse wrapper for improved decoding of HTTP bulk responses#649
BulkResponse wrapper for improved decoding of HTTP bulk responses#649Conversation
There was a problem hiding this comment.
tests.py is the entrypoint for zope.testing to discover test cases. Many utility functions had to be refactored away from here, in order to avoid circular imports.
7ef36cd to
ccbffd2
Compare
matriv
left a comment
There was a problem hiding this comment.
Thx for improving the bulk response handling. Left some comments.
ccbffd2 to
ea27b3e
Compare
50347d4 to
433dfdf
Compare
4da893a to
6a58353
Compare
| self.assertEqual(result, [{"rowcount": 1}, {"rowcount": -2}]) | ||
|
|
||
| # Verify decoded response. | ||
| bulk_response = BulkResponse(invalid_records, result) |
There was a problem hiding this comment.
Looking at this more carefully, I don't like that BulkResponse is something you need con construct manually. Couldn't we directly return it from the insert execution, instead of a list of BulkResultItem?
There was a problem hiding this comment.
Hi. I don't think we can do anything like this here, because the Python database driver must adhere to the Python Database API Specification, so the BulkResponse is just meant as an optional extension to it.
There was a problem hiding this comment.
af32409, just added, provides a bit of documentation for that extension in the section about bulk operations.
mfussenegger
left a comment
There was a problem hiding this comment.
Could you elaborate a bit more on the motivation for this?
Seems to me as if getting the info without this is not really that much more difficult.
|
Hi @mfussenegger,
The idea is to have a concise code representation over here, for the Because CrateDB Toolkit is rather heavy, and I wanted to make it reusable, I wanted to add it elsewhere. Another option would be to use the now separate cratedb-sqlalchemy package. |
That kinda confirms my point in that there's not much more code without the BulkResponse wrapper: cursor = self.connection.execute(statement=statement, parameters=operation.parameters)
self.connection.commit()
cratedb_bulk_result = getattr(cursor.context, "last_executemany_result", None)
failed_records = 0
success_count = 0
for result in cratedb_bulk_result:
if result["rowcount"] == -2:
failed_records += 1
else:
success_count += 1
self._metrics.count_success_total += success_count
self.progress_bar and self.progress_bar.update(n=success_count)This to me would even be more readable as it avoids the additional indirection. Also, given that the DB API spec says:
I think we could extend our return value - as long as we can keep it compatible with the existing one. |
... when another CrateDB is running on the default port 4200.
`tests.py` is the entrypoint file that will be used by `zope.testing` to discover the test cases on behalf of what's returned from `test_suite`. It is better to not overload it with other support code that may also be needed in other contexts.
git mv src/crate/client/test* tests/client/ git mv src/crate/testing/test* tests/testing/
CrateDB HTTP bulk responses include `rowcount=` items, either signalling if a bulk operation succeeded or failed. - success means `rowcount=1` - failure means `rowcount=-2` https://cratedb.com/docs/crate/reference/en/latest/interfaces/http.html#error-handling
aaf9ca6 to
a016130
Compare
About
CrateDB HTTP bulk responses include
rowcount=items, either signalling if a bulk operation succeeded or failed.rowcount=1rowcount=-2https://cratedb.com/docs/crate/reference/en/latest/interfaces/http.html#error-handling
References
The code is coming from CrateDB Toolkit, but is generally usable beyond there.