fix(preview): accept deprecated field= kwarg on PreviewTextQuery#665
Merged
Conversation
Restores call-site compatibility for callers written against pre-rename PreviewTextQuery (single-field text scoring). `field=...` is now an accepted alias that migrates to `fields=[field]` and emits a DeprecationWarning; the canonical attribute is still `fields`. - `field` declared on the canonical msgspec.Struct (no parallel class) - `omit_defaults=True` keeps the wire payload clean — no `"field": null` - Backend's legacy single-field response variant now decodes correctly - Reject both-set and neither-set with ValueError
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
The rename
PreviewTextQuery.field(str) →PreviewTextQuery.fields(list[str]) atfefc4850is a breaking call-site change for any user written against pre-renamePreviewTextQuery. The preview namespace's documented SemVer policy permits this, but the cost is small to make it non-breaking, so this PR does.field=is reintroduced as a deprecated kwarg/attribute on the canonicalmsgspec.Struct(no parallel class, per the shim-purity convention).fields=[field]in__post_init__and emits aDeprecationWarning.omit_defaults=Truekeeps the encoded payload free of a"field": nullartifact; existing wire-shape tests are unchanged.{"type": "text", "field": "...", "query": "..."}) now works and routes through the same migration path.field=andfields=raisesValueError; passing neither raisesValueError.Why
Avoids breaking callers without forcing a re-design of the preview API. The backend already accepts both wire forms, so this only restores the Python-side call signature.
Test plan
uv run pytest tests/unit/preview/models/test_score_by.py— 21/21 pass, including 6 new tests covering the deprecation pathuv run pytest tests/unit/preview/— 705 passed, 1 xfailed (no regressions)uv run mypy --strict pinecone/— clean across 186 source filesuv run ruff check+ruff format --check— cleantests/integration/preview/— out of scope for this PR (no behavior change on the wire)Note
Low Risk
Low risk: changes are confined to preview model initialization/serialization with added validation and tests; main risk is tightening constructor requirements for callers who passed neither
fieldsnorfield.Overview
Restores backward compatibility for
PreviewTextQueryby reintroducing deprecatedfieldsupport that auto-migrates tofields=[...]and emits aDeprecationWarning, while enforcing that callers provide exactly one offieldorfields.Ensures JSON encoding stays canonical (no
"field": null) viaomit_defaults=True, and adds unit coverage for migration, validation errors, and decoding the legacy backend{"field": ...}variant.Reviewed by Cursor Bugbot for commit c559ac0. Bugbot is set up for automated code reviews on this repo. Configure here.