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)
| 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 | """ |
no test coverage detected