fix(invoke5): warn on unknown v5 fields without breaking parsing#267
Merged
Conversation
``GenerationMetadata5`` carries ``extra="allow"`` intentionally: InvokeAI's v5 metadata schema is actively extended between releases, and silently dropping a new upstream field is preferable to refusing to parse the image. The trade-off is reduced visibility into schema drift — the previous behavior was completely silent, so new fields slipped through unnoticed. Adds a ``model_validator(mode="after")`` hook on ``GenerationMetadata5`` that walks ``self.__pydantic_extra__`` (Pydantic's storage for ``extra="allow"``'d fields) and logs each new field name once per process via a module-level ``_warned_extra_fields`` set. Subsequent images carrying the same field are silent — the goal is "did anything new show up?", not per-image instrumentation, so log volume stays proportional to the number of distinct schema additions seen. Behavior preserved end-to-end: parsing still succeeds for any v5 payload regardless of unknown fields; the warning is purely observability. Four new tests cover: * Unknown fields trigger a warning (and known ones don't). * Same-named fields seen twice only warn once. * New fields seen after a known one fire a fresh warning that doesn't re-mention the already-known ones. * Multiple unknown fields in one payload coalesce into one warning with all names listed. Per-test fixture clears ``_warned_extra_fields`` so test order doesn't influence what counts as first-seen. 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.
Why this exists
`GenerationMetadata5` carries `extra="allow"` intentionally — InvokeAI's v5 metadata schema is actively extended between releases, and silently dropping a new upstream field is preferable to refusing to parse the image. The trade-off has been zero visibility into schema drift: new fields slipped through entirely unnoticed.
What lands
A `model_validator(mode="after")` hook on `GenerationMetadata5` walks `self.pydantic_extra` (Pydantic v2's storage for `extra="allow"`'d fields) and logs each unknown field name once per process via a module-level `_warned_extra_fields` set. Subsequent images carrying the same field are silent — the goal is "did anything new show up?", not per-image instrumentation, so log volume stays proportional to the number of distinct schema additions seen.
Sample log output (single warning per field, lifetime of the process):
```
WARNING invoke5metadata: InvokeAI v5 metadata contains field(s) not declared
in GenerationMetadata5: new_field_x, new_field_y. Parsing succeeded
via extra='allow'; add to the schema if useful in the drawer or
recall payload.
```
Behavior preserved
Test plan
Four new tests cover the contract:
The fixture clears `_warned_extra_fields` around each test so test order doesn't influence what counts as first-seen.
Net +119 lines (38 in the schema file for the validator + module-level comment, 81 for the four tests).
🤖 Generated with Claude Code