Conversation
Pydantic 2.11 deprecated accessing `model_fields` on a model instance (removed in Pydantic 3.0). Replace the 8 `self.model_fields` reads in the schema `compose()` methods with `type(self).model_fields`. `model_fields` is a class-level attribute, so class vs instance access returns the same mapping and behaviour is unchanged; these loops only use the field names (via `getattr(self, field)`). The `cls.model_fields` sites in classmethods were already correct and are left untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merged
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.
What
Pydantic 2.11 deprecated accessing
model_fieldson a model instance (and Pydantic 3.0 removes it). This replaces the 8self.model_fieldsreads in the schemacompose()methods withtype(self).model_fields.Files:
commodity.py,impact.py,region.py(×2),storage.py,technology.py(×2),trade.py.Why it's safe
model_fieldsis a class-level attribute — class vs instance access returns the same mapping, so behaviour is identical.getattr(self, field)); theFieldInfovalue is discarded.cls.model_fieldssites (in classmethods) were already correct and are left untouched.Verification
pytest tests/test_construction/→ 35 passed, 2 skipped; thePydanticDeprecatedSince211: … 'model_fields' … on the instancewarnings (previously emitted on every model construction) are gone.grep -rn 'self\.model_fields' tz/→ no results.Scope
Standalone cleanup, independent of the in-flight linopy 0.7 migration (disjoint files). Completes Pydantic-3.0 readiness for this symbol — no other deprecated instance-access (
__fields__,model_computed_fields) exists in the package.🤖 Generated with Claude Code