Commit 40092d3c authored by Yury's avatar Yury

document: allow returning none if related document doesnt exist

parent 88bf47c0
Pipeline #327 passed with stages
in 4 minutes and 55 seconds
......@@ -62,11 +62,9 @@ build:
stage: pypi_build
tags:
- docker
image: alpine
image: python:latest
script:
- apk update
- apk add --update --no-cache --virtual .build-deps alpine-sdk python3-dev musl-dev postgresql-dev libffi-dev
- pip3 install -U --upgrade setuptools pip twine setuptools wheel
- python3 setup.py sdist bdist_wheel
- pip install -U --upgrade setuptools pip twine setuptools wheel
- python setup.py sdist bdist_wheel
- twine upload dist/*
......@@ -61,7 +61,7 @@ class DocumentField:
def __eq__(self, other: "DocumentField"):
try:
return self.document_cls is other.document_cls and self.name == other.name
return self.document_cls is other.document_cls and self.name == other.name
except AttributeError:
raise TypeError(f"Can't compare {other} to DocumentField.")
......@@ -316,12 +316,15 @@ class Document(metaclass=MetaDocument):
async def fget(self):
field = DocumentField(self.__class__, self_field)
if multiple:
return await other_field.document_cls.many(
**{other_field.name: self[field.name]})
else:
return await other_field.document_cls.one(
**{other_field.name: self[field.name]})
try:
if multiple:
return await other_field.document_cls.many(
**{other_field.name: self._document_.get(field.name)})
else:
return await other_field.document_cls.one(
**{other_field.name: self._document_.get(field.name)})
except DocumentDoesntExist:
return
result = property(fget=fget)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment