fix(query): _handle_keyword coerces non-iterable values to single-element list (#152)#153
Merged
Merged
Conversation
…ment list (#152) Previous: 'query_val = [query_val] if isinstance(query_val, str) else list(query_val)' assumed value is str or iterable. A Zope DateTime / Python datetime / int hit list(value) and raised TypeError: object is not iterable. Now: treat list/tuple/set/frozenset as iterable-of-keywords, everything else as single-value scalar. Coerce with str() to match JSONB storage shape. Closes #152. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #152. Another ZCatalog-compat rough edge exposed after the b61 deploy freed up the code path.
Bug
```python
_handle_keyword
query_val = [query_val] if isinstance(query_val, str) else list(query_val)
```
This assumes the value is either a `str` or iterable. A Zope `DateTime`, Python `datetime`, plain `int`, or any other non-iterable scalar hits `list(value)` and raises `TypeError: 'DateTime' object is not iterable`.
Observed on aaf-6 prod via `plone.app.querystring.querybuilder.html_results` (Collection edit widget live-preview) where a caller routed a `DateTime` through a keyword-index criterion by mistake.
Fix
Treat only true iterables (`list`, `tuple`, `set`, `frozenset`) as collections; anything else — string, scalar, or object with `str` but no `iter` — is a single-value scalar. All values are coerced to `str()` to match the JSONB storage shape (keyword arrays always contain strings).
Why not block upstream instead
The upstream root cause is a buggy caller passing the wrong type. But the pgcatalog `TypeError` is too brittle — it surfaces as a 500 error for end users. The robust fix is to coerce silently; the upstream bug can be chased separately but should not take down renders.
Test plan
🤖 Generated with Claude Code