Skip to content

fix(preview): accept deprecated field= kwarg on PreviewTextQuery#665

Merged
jhamon merged 1 commit into
mainfrom
backcompat/preview-text-query-field-alias
May 13, 2026
Merged

fix(preview): accept deprecated field= kwarg on PreviewTextQuery#665
jhamon merged 1 commit into
mainfrom
backcompat/preview-text-query-field-alias

Conversation

@jhamon
Copy link
Copy Markdown
Collaborator

@jhamon jhamon commented May 13, 2026

Summary

The rename PreviewTextQuery.field (str) → PreviewTextQuery.fields (list[str]) at fefc4850 is a breaking call-site change for any user written against pre-rename PreviewTextQuery. 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 canonical msgspec.Struct (no parallel class, per the shim-purity convention).
  • When provided, it migrates to fields=[field] in __post_init__ and emits a DeprecationWarning.
  • omit_defaults=True keeps the encoded payload free of a "field": null artifact; existing wire-shape tests are unchanged.
  • Decoding the legacy single-field backend response variant ({"type": "text", "field": "...", "query": "..."}) now works and routes through the same migration path.
  • Mutually exclusive: passing both field= and fields= raises ValueError; passing neither raises ValueError.

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 path
  • uv run pytest tests/unit/preview/ — 705 passed, 1 xfailed (no regressions)
  • uv run mypy --strict pinecone/ — clean across 186 source files
  • uv run ruff check + ruff format --check — clean
  • Integration tests in tests/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 fields nor field.

Overview
Restores backward compatibility for PreviewTextQuery by reintroducing deprecated field support that auto-migrates to fields=[...] and emits a DeprecationWarning, while enforcing that callers provide exactly one of field or fields.

Ensures JSON encoding stays canonical (no "field": null) via omit_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.

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
@jhamon jhamon merged commit 3758724 into main May 13, 2026
13 checks passed
@jhamon jhamon deleted the backcompat/preview-text-query-field-alias branch May 13, 2026 18:46
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.

1 participant