MCPcopy
hub / github.com/ormar-orm/ormar / model_construct

Method model_construct

ormar/models/newbasemodel.py:1180–1207  ·  view source on GitHub ↗
(
        cls: type["T"], _fields_set: Optional["SetStr"] = None, **values: Any
    )

Source from the content-addressed store, hash-verified

1178
1179 @classmethod
1180 def model_construct(
1181 cls: type["T"], _fields_set: Optional["SetStr"] = None, **values: Any
1182 ) -> "T":
1183 own_values = {
1184 k: v for k, v in values.items() if k not in cls.extract_related_names()
1185 }
1186 model = cls.__new__(cls)
1187 fields_values: dict[str, Any] = {}
1188 for name, field in cls.model_fields.items():
1189 if name in own_values:
1190 fields_values[name] = own_values[name]
1191 elif not field.is_required():
1192 fields_values[name] = field.get_default()
1193 fields_values.update(own_values)
1194
1195 if _fields_set is None:
1196 _fields_set = set(values.keys())
1197
1198 extra_allowed = cls.model_config.get("extra") == "allow"
1199 if not extra_allowed:
1200 fields_values.update(values)
1201 object.__setattr__(model, "__dict__", fields_values)
1202 model._initialize_internal_attributes()
1203 cls._construct_relations(model=model, values=values)
1204 object.__setattr__(model, "__pydantic_fields_set__", _fields_set)
1205 return cls._pydantic_model_construct_finalizer(
1206 model=model, extra_allowed=extra_allowed, values=values
1207 )
1208
1209 @classmethod
1210 def _pydantic_model_construct_finalizer(

Calls 9

extract_related_namesMethod · 0.80
get_defaultMethod · 0.80
_construct_relationsMethod · 0.80
__new__Method · 0.45
updateMethod · 0.45
getMethod · 0.45
__setattr__Method · 0.45