Skip to content

fix: do not treat str/bytes as sequences in Query.any/all - #641

Merged
msiemens merged 1 commit into
msiemens:masterfrom
uadhran:fix/638-any-all-exclude-str-bytes
Oct 5, 2026
Merged

msiemens merged 1 commit into
msiemens:masterfrom
uadhran:fix/638-any-all-exclude-str-bytes

Conversation

@uadhran

@uadhran uadhran commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Query.any / Query.all used hasattr(obj, '__iter__') for sequence checks, so string fields were treated as character sequences and could false-match (e.g. name.any(['a', 'b']) on 'abc').

Per discussion on #638, option (1): treat real sequences only and exclude str / bytes (also bytearray).

Fixes #638

Test plan

  • uv run py.test tests/test_queries.py -q --mypy
  • Existing list-based any/all tests still pass
  • New assertions: string fields do not match any/all as char lists

is_sequence() used hasattr(__iter__), so string fields matched
any/all as character lists (e.g. name.any(['a','b']) on 'abc').

Use collections.abc.Sequence and exclude str/bytes/bytearray.

Fixes msiemens#638
@msiemens

msiemens commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Thanks!

@msiemens
msiemens merged commit 6d7c4fc into msiemens:master Oct 5, 2026
31 checks passed
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.

Query.any/all treat strings as sequences, causing false matches

2 participants