Repository navigation
Conversation
… reports without the flag Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
vawsgit
left a comment
There was a problem hiding this comment.
✅ LGTM!
Checked at 4aa668f2. The merge base is dev 0a4820f4. The diff touches only docs/docs/Advanced/dynamic-models.md, and git diff --stat origin/dev HEAD -- src tests is empty.
Measured on dev 0a4820f4 (PYTHONPATH=<dev>/src, with inspect.getfile(stickler) pointing at that tree). Each line below is explain() output, showing comparator, threshold and source:
| Model | vendor: str |
color: str |
|---|---|---|
model_from_json, infer_unspecified_fields: true |
Levenshtein 0.85 name-token |
Levenshtein 0.7 type |
from_json_schema, x-aws-stickler-infer-unspecified |
Levenshtein 0.85 name-token |
Levenshtein 0.7 type |
from_json_schema, no flag |
Levenshtein 0.5 explicit |
Levenshtein 0.5 explicit |
- The new
vendorrow is right: the 0.85 comes from the name.labelandissued_datealso get 0.7type, so 0.7 is thestrdefault. - The new
colorrow is right in both columns. - The new
explain()sentence is right. With no flag,totalandpaid(left at the type default) also report 0.5explicit.
Issue keyword. Part of #489 is right.
- Item 1 is already done on
dev.dynamic-models.md:346names all three nested field types. - Item 2 is done by this PR.
- Item 3 is partly done. See the optional inline note:
from_pydantic()and hand-writtenStructuredModelclasses still reportexplicitfor fields Stickler chose. #489 should stay open for that.
No CI checks are reported on this head yet. I did not run the suite, because the PR changes no code or tests.
| `stickler.evaluate()` reports, so the two paths read alike. | ||
|
|
||
| A model built with `from_json_schema()` and no inference flag infers nothing, so | ||
| `explain()` reports every field as `explicit`, including fields left at the type default. |
There was a problem hiding this comment.
Optional, not blocking. This sentence is true, but from_json_schema() is not the only case. On dev 0a4820f4, explain() also reports explicit for fields Stickler chose in these two cases:
from_pydantic(P) # class P(BaseModel): vendor: str; color: str; total: float
vendor LevenshteinComparator 0.85 explicit
color LevenshteinComparator 0.7 explicit
total NumericComparator 0.95 explicit
class H(StructuredModel): a: str = ComparableField(); vendor: str; color: str
a LevenshteinComparator 0.5 explicit
vendor LevenshteinComparator 0.7 explicit
eval_for(P) on the plain Pydantic class reports name-token / type for the same fields. So the line above, "source is explicit for a field you configured", is still not true for those two paths. That is #489 item 3's remaining case. You can widen this sentence here or leave it to a follow-up. Part of #489 already keeps the issue open.
There was a problem hiding this comment.
Thanks for naming the two cases. I reproduced both on the dev branch tip with PYTHONPATH=src. from_pydantic(P) reports explicit at 0.85, 0.7 and 0.95 for vendor, color and total. The StructuredModel class reports explicit for all three fields. eval_for(P) on the plain Pydantic class reports name-token, type and name-token.
I widened the sentence in 540bc2f. It now says explicit is not always a field you configured, and it covers from_json_schema() with no flag, from_pydantic() and hand-written StructuredModel classes. The change touches only this docs file. I did not run the full suite or the docs build on this head. Part of #489 stays, because the explain() source behaviour itself is unchanged.
… report explicit Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
sromoam
left a comment
There was a problem hiding this comment.
Thanks @MaxonT, and thanks for picking up vawsgit's note so quickly. I checked 540bc2f8, which merges cleanly into current dev (ce0f710b). Both table rows are right: vendor: str gets Levenshtein 0.85 name-token and color: str gets 0.7 type through model_from_json and from_json_schema with the flag, and both get 0.5 explicit from from_json_schema without it. The docs check (make -C docs check) passes with only the six known griffe warnings. The sentence widened in 540bc2f says one thing the code doesn't do, though.
Must fix
- A hand-written
StructuredModeltakes nothing from the name, and a barefloatorintstays onLevenshteinComparator(dynamic-models.md:485-487). The new sentence says its fields reportexplicit"even where Stickler picked the comparator from the type or the name". On this head,class H(StructuredModel): total: float; invoice_id: int; vendor: strgives all threeLevenshteinComparator@ 0.7, andtotal100.0 against 100.5 scores 0.8 by edit distance. vawsgit's repro shows the same forvendor: 0.7, not the 0.85 its name gets on the inference path.thresholds-and-metrics.md:158already says a bareintorfloatis compared as text, so the two pages now disagree, and a reader of this one would expecttotal: floatto getNumericComparator. Suggestion inline.
Smaller
-
"auto"infers without the flag (:484). With no object-level key and"total": {"type": "number", "x-aws-stickler-comparator": "auto"},explain()reportstotalasNumericComparator0.95name-token, so "infers nothing" does not hold there. The page calls only the model-level key the flag (:435). The same suggestion covers it. -
Point to the real trail for a Pydantic class (
:485).stickler.eval_for(P).explain()on the plain class reportsname-tokenandtype, with the same comparators and thresholds thatfrom_pydantic(P)reports asexplicit. One clause saying so, as #489's proposed fix does, gives the reader something to do about the caveat. Also in the suggestion. -
CHANGELOG. Readers could have taken 0.85 as the
strdefault andexplicitas "you configured this", so a### Documentationline under[Unreleased]fits (RELEASING.md, "What belongs in the changelog"). Something like:- Dynamic Model Creation no longer reads as if 0.85 were the `str` default: `vendor: str` gets it from its name, and a `str` field that no name rule matches gets 0.7. The page also says when `explain()` reports `explicit` for a field you did not configure ([#489](https://github.com/awslabs/stickler/issues/489)).
One heads-up: we're not merging anything outside the 1.1.0 milestone until 1.1.0 lands, so this will wait until after that even once it's ready.
| `explicit` is not always a field you configured. A model built with `from_json_schema()` | ||
| and no inference flag infers nothing, so `explain()` reports every field as `explicit`, | ||
| including fields left at the type default. A model from `from_pydantic()`, or a | ||
| hand-written `StructuredModel` class, does the same: its fields report `explicit` even | ||
| where Stickler picked the comparator from the type or the name. |
There was a problem hiding this comment.
Must fix 1 and Smaller 1 and 2. Measured on 540bc2f8:
class H(StructuredModel): total: float; invoice_id: int; vendor: str
total LevenshteinComparator 0.7 explicit
invoice_id LevenshteinComparator 0.7 explicit
vendor LevenshteinComparator 0.7 explicit
from_json_schema, no object-level key, "x-aws-stickler-comparator": "auto" on total
vendor LevenshteinComparator 0.5 explicit
total NumericComparator 0.95 name-token
With this applied, the docs check still passes and the link resolves.
| `explicit` is not always a field you configured. A model built with `from_json_schema()` | |
| and no inference flag infers nothing, so `explain()` reports every field as `explicit`, | |
| including fields left at the type default. A model from `from_pydantic()`, or a | |
| hand-written `StructuredModel` class, does the same: its fields report `explicit` even | |
| where Stickler picked the comparator from the type or the name. | |
| `explicit` is not always a field you configured. A model from `from_json_schema()` | |
| infers only the fields that `x-aws-stickler-infer-unspecified` or | |
| `x-aws-stickler-comparator: "auto"` reaches, so every other field reports `explicit`, | |
| including fields left at the type default. A model from `from_pydantic()` reports | |
| `explicit` for every field, even where Stickler picked the comparator from the type or | |
| the name; run `stickler.eval_for()` on the Pydantic class itself to see `type` and | |
| `name-token`. A hand-written `StructuredModel` class also reports `explicit` for every | |
| field, but nothing there is picked from the name, and a bare `int` or `float` field is | |
| compared as text by `LevenshteinComparator` (see | |
| [Precedence, in one line](../Getting-Started/thresholds-and-metrics.md#precedence-in-one-line)). |
…gelog entry Address the review on 540bc2f: the explicit paragraph now matches the measured output for from_json_schema() with and without the flag (including "auto"), from_pydantic(), and hand-written StructuredModel classes, with a link to the threshold precedence table. Add a Documentation entry under [Unreleased]. Part of awslabs#489. Signed-off-by: Ym <173550318+MaxonT@users.noreply.github.com>
|
Thanks for catching this, and for the repro and suggested wording. I pushed d23eb45, which uses your paragraph. It now says I also added the |
Following up on the claim I left on #489, this covers the two items I said I would take, as far as they are still true on dev.
This covers the parts of #489 that are still true on current
dev. I claimed items 2 and 3 on the issue; item 1 (wherematch_thresholdis read) already lists all three nested field types ondev, so I left it alone.Item 2: the "What inference chooses" table labels rows by type, so
vendor: strreads as if 0.85 were thestrdefault. It comes from the namevendor. Astrfield with no matching name getsLevenshteinComparatorat 0.7. I added that row and noted the name on thevendorrow.Item 3, what is left of it: the sentence under the
explain()example is already correct for fields that were configured or inferred, and the code now reports the inference trail instead ofexplicit. One case still reads differently from what a reader expects: a model built withfrom_json_schema()and no inference flag reports every field asexplicit, including fields left at the type default, because nothing was inferred. I added one sentence saying so.Part of #489, so I am not using "Fixes". The issue's wording of item 3 and its other sentences I did not change.
How was this tested?
pip install -e .in a clean venv (the printedsticklerpath is the checkout):model_from_jsonwithinfer_unspecified_fieldsgivesvendor: strLevenshtein 0.85name-tokenandcolor: strLevenshtein 0.7type;from_json_schema()without the flag gives both fields Levenshtein 0.5explicit.mkdocs buildfromdocs/exits 0 and the new table row is in the renderedAdvanced/dynamic-modelspage.make docs-buildwith--frozenthrough uv, the link checker, and the test suite (docs only, no code or test files touched).