PY: fix resourceType shadow warnings on family base types#191
Merged
Conversation
Concrete resources subclass the abstract family types (Resource, DomainResource). The fhirpy base model registers resourceType as a class attribute from the field default, which the subclasses then shadow, producing Pydantic UserWarnings on import. Omit the default on family/abstract types (their resourceType becomes a required str validated by pattern) so no class attribute is registered, and guard the fhirpy registration against PydanticUndefined.
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.
Follow-up to #190.
Importing the generated package emitted Pydantic
UserWarning: Field name "resourceType" ... shadows an attribute in parentfor every concrete resource. The fhirpy base model registersresourceTypeas a class attribute from the field default in__pydantic_init_subclass__; concrete resources subclassing the abstract family types (Resource,DomainResource) then "shadow" that attribute.defaulton family/abstract types so no class attribute is registered. TheirresourceTypebecomes a requiredstrvalidated bypattern(these types are never instantiated directly).PydanticUndefinedso required fields are skipped.sql-on-fhir,local-package) and regenerate thepython-r4-us-coreexample.Before (abstract base registered a class attribute that subclasses shadowed):
After (no default → no class attribute → no shadow warning):
Concrete resources still expose
cls.resourceTypefor fhirpy, keep their default, and reject mismatched values.