tortoise-orm icon indicating copy to clipboard operation
tortoise-orm copied to clipboard

QuerySetSingle behavior inconsistency

Open Yaroher2442 opened this issue 3 years ago • 3 comments

    def get_or_none(self, *args: Q, **kwargs: Any) -> QuerySetSingle[Optional[MODEL]]:
        """
        Fetch exactly one object matching the parameters.
        """
        queryset = self.filter(*args, **kwargs)
        queryset._limit = 2
        queryset._single = True
        return queryset  # type: ignore

queryset._limit = 2 Why get_or_none uses limit 2? It is not an expected behavior.

Yaroher2442 avatar Feb 28 '22 14:02 Yaroher2442

Just noticed the same

sasha-id avatar Sep 16 '22 03:09 sasha-id

Becase MultipleObjectsReturned detection

long2ice avatar Sep 16 '22 04:09 long2ice

But you can use first instead

long2ice avatar Sep 16 '22 04:09 long2ice