@@ -106,24 +106,24 @@ class DiffSyncModel(BaseModel):
106
106
"""Message, if any, associated with the create/update/delete status value."""
107
107
model_config = ConfigDict (arbitrary_types_allowed = True )
108
108
109
- def __init_subclass__ (cls ) -> None :
109
+ @classmethod
110
+ def __pydantic_init_subclass__ (cls , ** kwargs : Any ) -> None :
110
111
"""Validate that the various class attribute declarations correspond to actual instance fields.
111
112
112
113
Called automatically on subclass declaration.
113
114
"""
114
- variables = cls .__fields__ .keys ()
115
115
# Make sure that any field referenced by name actually exists on the model
116
116
for attr in cls ._identifiers :
117
- if attr not in variables and not hasattr (cls , attr ):
117
+ if attr not in cls . model_fields and not hasattr (cls , attr ):
118
118
raise AttributeError (f"_identifiers { cls ._identifiers } references missing or un-annotated attr { attr } " )
119
119
for attr in cls ._shortname :
120
- if attr not in variables :
120
+ if attr not in cls . model_fields :
121
121
raise AttributeError (f"_shortname { cls ._shortname } references missing or un-annotated attr { attr } " )
122
122
for attr in cls ._attributes :
123
- if attr not in variables :
123
+ if attr not in cls . model_fields :
124
124
raise AttributeError (f"_attributes { cls ._attributes } references missing or un-annotated attr { attr } " )
125
125
for attr in cls ._children .values ():
126
- if attr not in variables :
126
+ if attr not in cls . model_fields :
127
127
raise AttributeError (f"_children { cls ._children } references missing or un-annotated attr { attr } " )
128
128
129
129
# Any given field can only be in one of (_identifiers, _attributes, _children)
@@ -147,15 +147,15 @@ def dict(self, **kwargs: Any) -> Dict:
147
147
"""Convert this DiffSyncModel to a dict, excluding the diffsync field by default as it is not serializable."""
148
148
if "exclude" not in kwargs :
149
149
kwargs ["exclude" ] = {"diffsync" }
150
- return super ().dict (** kwargs )
150
+ return super ().model_dump (** kwargs )
151
151
152
152
def json (self , ** kwargs : Any ) -> StrType :
153
153
"""Convert this DiffSyncModel to a JSON string, excluding the diffsync field by default as it is not serializable."""
154
154
if "exclude" not in kwargs :
155
155
kwargs ["exclude" ] = {"diffsync" }
156
156
if "exclude_defaults" not in kwargs :
157
157
kwargs ["exclude_defaults" ] = True
158
- return super ().json (** kwargs )
158
+ return super ().model_dump_json (** kwargs )
159
159
160
160
def str (self , include_children : bool = True , indent : int = 0 ) -> StrType :
161
161
"""Build a detailed string representation of this DiffSyncModel and optionally its children."""
@@ -855,4 +855,4 @@ def count(self, model: Union[StrType, "DiffSyncModel", Type["DiffSyncModel"], No
855
855
856
856
857
857
# DiffSyncModel references DiffSync and DiffSync references DiffSyncModel. Break the typing loop:
858
- DiffSyncModel .update_forward_refs ()
858
+ DiffSyncModel .model_rebuild ()
0 commit comments