ENG-9860 fix(vars): preserve custom Field attributes in state metaclass#6726
Conversation
BaseStateMeta rebuilt Field instances for state annotations, discarding any custom attributes callers had set. Copy over attrs the rebuilt field did not recompute via Field._copy_custom_attrs_from so subclassed or customized fields keep their extra state.
Greptile SummaryThis PR fixes
Confidence Score: 5/5Safe to merge — the change is additive, well-contained, and backed by targeted tests. The copy loop runs strictly after all standard Field.init processing so it cannot overwrite computed type or default attrs. The annotation guard correctly prevents the one known duck-typing hazard. copy.deepcopy per-attribute handles the mutable aliasing edge case. All three rebuild sites in BaseStateMeta were updated consistently, and five tests cover the key scenarios. No files require special attention. Important Files Changed
Reviews (2): Last reviewed commit: "fix(vars): deep-copy custom Field attrs ..." | Re-trigger Greptile |
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f368d27a9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
masenf
left a comment
There was a problem hiding this comment.
i think this copying functionality should be part of __init__; you can add another optional param source_field and apply the copying of extra values from there.
what greptile says about deepcopying the values makes sense to me, we don't want to have shared references to mutable types across different Field instances.
having a list of reserved attributes also makes sense to avoid misidentification with pydantic fields.
add changelog entry
Fold custom-attribute copying into Field.__init__ via a source_field parameter instead of the post-hoc _copy_custom_attrs_from helper. Copied attrs are now deep-copied so mutable values aren't shared between the original and rebuilt fields, and the reserved `annotation` attribute is never carried over — get_field_type duck-types pydantic fields on `.annotation`, so copying it would shadow the real class annotation.
BaseStateMeta rebuilt Field instances for state annotations, discarding any custom attributes callers had set. Copy over attrs the rebuilt field did not recompute via Field._copy_custom_attrs_from so subclassed or customized fields keep their extra state.
All Submissions:
Type of change
Please delete options that are not relevant.
New Feature Submission:
Changes To Core Features: