fix: resolve unhashable type slice in ParallelQuery - #714
Conversation
This handles cases where the database response is a dictionary instead of a list, avoiding unhashable type errors when slicing.
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash in ParallelQuery.do_batch when ApertureDB returns a dictionary-shaped response (instead of the expected list) under certain failure/partial-failure conditions, which previously led to slicing/iteration errors (TypeError: unhashable type: 'slice'). It also cleans up type checking by replacing issubclass(type(x), y) with the more idiomatic isinstance(x, y).
Changes:
- Guarded
ParallelQuery.do_batchresult==2 stats computation behindisinstance(r, list)and added a safe fallback for non-list responses. - Replaced non-idiomatic runtime type checks with
isinstanceinParallelQuery.pyandCommonLibrary.py. - Adjusted response slicing logic to use
isinstance(response, list)consistently in response-to-handler mapping.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| aperturedb/ParallelQuery.py | Prevents crashes when batch_command returns a dict response and updates type-checking style. |
| aperturedb/CommonLibrary.py | Uses isinstance for response shape checks to avoid incorrect list assumptions when slicing/mapping responses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Added `test_dictResponseHandling` in `test_Parallel.py` to simulate a failed server response where `Connector.query` returns a dict instead of a list. This verifies that `ParallelQuery` does not raise an exception (like the previous "unhashable type: 'slice'" error) and properly records stats.
ad-claw000
left a comment
There was a problem hiding this comment.
Added a regression test to test_Parallel.py to simulate the failed server behavior returning a dict, verifying the fix and ensuring no regression. Fixed in 10eb649.
…sed mock patch import
…um() Addresses review comment in PR 714.
Summary
This PR resolves an issue in ParallelQuery where the database returns a dictionary response rather than a list of responses under certain failure conditions, resulting in a
TypeError: unhashable type: 'slice'.Verification
ParallelQuery.do_batchto properly checkisinstance(r, list)to prevent incorrect indexing or iterating over a dictionary response as if it were a list.issubclass(type(x), y)checks withisinstance(x, y)throughoutParallelQuery.pyandCommonLibrary.pyfor clarity and correctness.pytest test/to ensure existing behavior is preserved.Fixes #358