Skip to content

Commit

Permalink
Fix fallback model_fields class property
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 19, 2023
1 parent eba136b commit 5c29218
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions python/lsst/daf/butler/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def model_rebuild(
return None

else:
from astropy.utils.decorators import classproperty

class _BaseModelCompat(BaseModel): # type:ignore[no-redef]
"""Methods from pydantic v2 that can be used in pydantic v1."""
Expand Down Expand Up @@ -175,11 +176,15 @@ def model_dump_json(

@classmethod # type: ignore
def model_construct(cls, _fields_set: set[str] | None = None, **values: Any) -> Self:
# BaseModel.construct() is very close to what we previously
# implemented manually in each direct() method but does have one
# extra loop in it to fill in defaults and handle aliases.
return cls.construct(_fields_set=_fields_set, **values)

@property
def model_fields(self) -> dict[str, FieldInfo]: # type: ignore
return self.__fields__ # type: ignore
@classmethod
@classproperty
def model_fields(cls) -> dict[str, FieldInfo]: # type: ignore
return cls.__fields__ # type: ignore

@classmethod
def model_rebuild(
Expand Down

0 comments on commit 5c29218

Please sign in to comment.