Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add default parametter to HashModel.get #551

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aredis_om/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from .token_escaper import TokenEscaper


_INCOMPLETE = object()
model_registry = {}
_T = TypeVar("_T")
Model = TypeVar("Model", bound="RedisModel")
Expand Down Expand Up @@ -1532,9 +1533,11 @@ async def all_pks(cls): # type: ignore
)

@classmethod
async def get(cls: Type["Model"], pk: Any) -> "Model":
async def get(cls: Type["Model"], pk: Any, default:_INCOMPLETE) -> "Model":
document = await cls.db().hgetall(cls.make_primary_key(pk))
if not document:
if default is not _INCOMPLETE:
return default
raise NotFoundError
try:
result = cls.parse_obj(document)
Expand Down