diff --git a/.coverage b/.coverage index 9976a3e47..6a416ffac 100644 Binary files a/.coverage and b/.coverage differ diff --git a/ormar/fields/base.py b/ormar/fields/base.py index c08266447..f3e83a4f8 100644 --- a/ormar/fields/base.py +++ b/ormar/fields/base.py @@ -35,8 +35,7 @@ def default_value(cls) -> Optional[Field]: default = cls.default if cls.default is not None else cls.server_default if callable(default): return Field(default_factory=default) - else: - return Field(default=default) + return Field(default=default) return None @classmethod diff --git a/ormar/models/newbasemodel.py b/ormar/models/newbasemodel.py index f61362d0e..d30901c26 100644 --- a/ormar/models/newbasemodel.py +++ b/ormar/models/newbasemodel.py @@ -119,11 +119,11 @@ def __setattr__(self, name: str, value: Any) -> None: # noqa CCR001 def __getattribute__(self, item: str) -> Any: if item in ("_orm_id", "_orm_saved", "_orm", "__fields__"): return object.__getattribute__(self, item) - elif item != "_extract_related_names" and item in self._extract_related_names(): + if item != "_extract_related_names" and item in self._extract_related_names(): return self._extract_related_model_instead_of_field(item) - elif item == "pk": + if item == "pk": return self.__dict__.get(self.Meta.pkname, None) - elif item != "__fields__" and item in self.__fields__: + if item != "__fields__" and item in self.__fields__: value = self.__dict__.get(item, None) value = self._convert_json(item, value, "loads") return value diff --git a/ormar/queryset/queryset.py b/ormar/queryset/queryset.py index f6044c93d..4bc5e7f25 100644 --- a/ormar/queryset/queryset.py +++ b/ormar/queryset/queryset.py @@ -134,11 +134,11 @@ async def first(self, **kwargs: Any) -> "Model": async def get(self, **kwargs: Any) -> "Model": if kwargs: return await self.filter(**kwargs).get() + + if not self.filter_clauses: + expr = self.build_select_expression().limit(2) else: - if not self.filter_clauses: - expr = self.build_select_expression().limit(2) - else: - expr = self.build_select_expression() + expr = self.build_select_expression() rows = await self.database.fetch_all(expr)