diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e9dc7157c..04c6d693e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,6 +20,7 @@ Fixed - Fix mysql uuid compression bug (#1687) - Fix comment for fk fields without constraint for mysql (#1679) - Removed no_delay option for postgres, as it wasn't doing anything (#1677) +- Fix bug in `tortoise.models.Model` When a QuerySet uses the only function and then uses the print function to print the returned result, an AttributeError is generated. (#1723) 0.21.5 <../0.21.5>`_ - 2024-07-18 ------ diff --git a/tortoise/models.py b/tortoise/models.py index f16813c6c..f091c0ab3 100644 --- a/tortoise/models.py +++ b/tortoise/models.py @@ -781,7 +781,7 @@ def __eq__(self, other: object) -> bool: return type(other) is type(self) and self.pk == other.pk # type: ignore def _get_pk_val(self) -> Any: - return getattr(self, self._meta.pk_attr) + return getattr(self, self._meta.pk_attr, None) def _set_pk_val(self, value: Any) -> None: setattr(self, self._meta.pk_attr, value)