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

Method __setattr__

ormar/models/newbasemodel.py:248–276  ·  view source on GitHub ↗

Overwrites setattr in pydantic parent as otherwise descriptors are not called. :param name: name of the attribute to set :type name: str :param value: value of the attribute to set :type value: Any :return: None :rtype: None

(self, name: str, value: Any)

Source from the content-addressed store, hash-verified

246 return instance
247
248 def __setattr__(self, name: str, value: Any) -> None: # noqa CCR001
249 """
250 Overwrites setattr in pydantic parent as otherwise descriptors are not called.
251
252 :param name: name of the attribute to set
253 :type name: str
254 :param value: value of the attribute to set
255 :type value: Any
256 :return: None
257 :rtype: None
258 """
259 prev_hash = hash(self)
260
261 if hasattr(self, name):
262 object.__setattr__(self, name, value)
263 else:
264 # let pydantic handle errors for unknown fields
265 super().__setattr__(name, value)
266
267 if self._onupdate_fields and name in self.ormar_config.model_fields:
268 self.__setattr_fields__.add(name)
269
270 # In this case, the hash could have changed, so update it
271 if name == self.ormar_config.pkname or self.pk is None:
272 object.__setattr__(self, "__cached_hash__", None)
273 new_hash = hash(self)
274
275 if prev_hash != new_hash:
276 self._update_relation_cache(prev_hash, new_hash)
277
278 def __getattr__(self, item: str) -> Any:
279 """

Callers 10

__init__Method · 0.45
_internal_constructMethod · 0.45
_internal_setMethod · 0.45
__hash__Method · 0.45
pk_columnMethod · 0.45
set_save_statusMethod · 0.45
model_constructMethod · 0.45
merge_instances_listMethod · 0.45

Calls 2

addMethod · 0.45

Tested by

no test coverage detected