Skip to content

Commit

Permalink
Small refactoring in ReferenceField
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzsochi committed Dec 28, 2017
1 parent ce5fb18 commit dff0d00
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions yadm/fields/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ class Doc(Document):
assert doc.rdoc.id == rdoc.id
assert doc.rdoc.i == 13
Or asynchronous:
Or with asyncio:
.. code-block:: python
rdoc = await doc.rdoc
assert rdoc.id == rdoc.id
assert rdoc.i == 13
assert doc.rdoc == rdoc.id
"""
import asyncio
"""
from bson import ObjectId
from bson.errors import InvalidId

Expand Down Expand Up @@ -116,13 +115,11 @@ def from_mongo(self, document, value):
if (rdc, value) in document.__qs__.cache:
return cache[(rdc, value)]
else:
qs = document.__db__.get_queryset(rdc, cache=cache)

from yadm.aio.database import AioDatabase # fail
if isinstance(document.__db__, AioDatabase):
if document.__db__.aio:
cache[(rdc, value)] = ref = Reference(value, document, self)
return ref
else:
qs = document.__db__.get_queryset(rdc, cache=cache)
doc = qs.find_one(value)
if doc is None: # pragma: no cover
doc = qs.read_primary().find_one(value, exc=BrokenReference)
Expand All @@ -143,7 +140,7 @@ class Reference(ObjectId):
This is awaitable:
doc = await reference
doc = await doc.reference
"""
document = None

Expand Down

0 comments on commit dff0d00

Please sign in to comment.