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

Method get_or_none

ormar/queryset/queryset.py:1123–1141  ·  view source on GitHub ↗

Gets a single row from the db matching the criteria set by args/kwargs. Behaves like :meth:`get` but returns ``None`` instead of raising ``NoMatch`` when no row matches. ``MultipleMatches`` is still raised when criteria are provided and more than one row matches.

(self, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

1121 return None
1122
1123 async def get_or_none(self, *args: Any, **kwargs: Any) -> Optional["T"]:
1124 """
1125 Gets a single row from the db matching the criteria set by args/kwargs.
1126
1127 Behaves like :meth:`get` but returns ``None`` instead of raising
1128 ``NoMatch`` when no row matches. ``MultipleMatches`` is still raised
1129 when criteria are provided and more than one row matches.
1130
1131 :raises MultipleMatches: when criteria are set (via ``filter``/``exclude``
1132 or args/kwargs) and more than one row matches them.
1133 :param kwargs: fields names and proper value types
1134 :type kwargs: Any
1135 :return: returned model or None
1136 :rtype: Optional[Model]
1137 """
1138 try:
1139 return await self.get(*args, **kwargs)
1140 except ormar.NoMatch:
1141 return None
1142
1143 async def get(self, *args: Any, **kwargs: Any) -> "T": # noqa: CCR001
1144 """

Callers 7

first_or_404Method · 0.45
test_model_getFunction · 0.45
get_or_noneFunction · 0.45

Calls 1

getMethod · 0.95

Tested by 7

first_or_404Method · 0.36
test_model_getFunction · 0.36
get_or_noneFunction · 0.36