Commit 3758724
authored
fix(preview): accept deprecated
## 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
- [x] `uv run pytest tests/unit/preview/models/test_score_by.py` — 21/21
pass, including 6 new tests covering the deprecation path
- [x] `uv run pytest tests/unit/preview/` — 705 passed, 1 xfailed (no
regressions)
- [x] `uv run mypy --strict pinecone/` — clean across 186 source files
- [x] `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)
<!-- CURSOR_SUMMARY -->
---
> [!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.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
c559ac0. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->field= kwarg on PreviewTextQuery (#665)1 parent 926eb9d commit 3758724
2 files changed
Lines changed: 77 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | | - | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
36 | 59 | | |
37 | 60 | | |
38 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
55 | 107 | | |
56 | 108 | | |
57 | 109 | | |
| |||
0 commit comments