Skip to content

fix: resolve unhashable type slice in ParallelQuery - #714

Merged
luisremis merged 9 commits into
developfrom
fix/issue-358
May 24, 2026
Merged

fix: resolve unhashable type slice in ParallelQuery#714
luisremis merged 9 commits into
developfrom
fix/issue-358

Conversation

@ad-claw000

Copy link
Copy Markdown
Contributor

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

  • Modified ParallelQuery.do_batch to properly check isinstance(r, list) to prevent incorrect indexing or iterating over a dictionary response as if it were a list.
  • Replaced non-idiomatic issubclass(type(x), y) checks with isinstance(x, y) throughout ParallelQuery.py and CommonLibrary.py for clarity and correctness.
  • Ran tests via pytest test/ to ensure existing behavior is preserved.

Fixes #358

This handles cases where the database response is a dictionary instead of a list, avoiding unhashable type errors when slicing.
Copilot AI review requested due to automatic review settings May 20, 2026 09:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_batch result==2 stats computation behind isinstance(r, list) and added a safe fallback for non-list responses.
  • Replaced non-idiomatic runtime type checks with isinstance in ParallelQuery.py and CommonLibrary.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.

Comment thread aperturedb/ParallelQuery.py
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 ad-claw000 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI review requested due to automatic review settings May 20, 2026 12:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread aperturedb/ParallelQuery.py
Comment thread test/test_Parallel.py Outdated
Copilot AI review requested due to automatic review settings May 23, 2026 03:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread aperturedb/ParallelQuery.py Outdated
Copilot AI review requested due to automatic review settings May 23, 2026 06:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread test/test_Parallel.py Outdated
Comment thread aperturedb/ParallelQuery.py Outdated
Copilot AI review requested due to automatic review settings May 23, 2026 17:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@luisremis
luisremis merged commit ef926b9 into develop May 24, 2026
6 checks passed
@luisremis
luisremis deleted the fix/issue-358 branch May 24, 2026 01:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ParallelQuery fails with "TypeError: unhashable type: 'slice'"

3 participants