Skip to content

Commit

Permalink
Fixes #6. by_id no longer attempts to convert any value passed to a…
Browse files Browse the repository at this point in the history
…n ObjectId. References can now be non-`ObjectId` values.
  • Loading branch information
anthonyjb committed Jul 12, 2016
1 parent 39df40c commit e7dd67c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
17 changes: 5 additions & 12 deletions mongoframes/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def reload(self, **kwargs):
@classmethod
def by_id(cls, id, **kwargs):
"""Get a document by ID"""
return cls.one({'_id': ObjectId(id)}, **kwargs)
return cls.one({'_id': id}, **kwargs)

@classmethod
def count(cls, filter=None, **kwargs):
Expand Down Expand Up @@ -566,17 +566,14 @@ def _dereference(cls, documents, references):
if not value:
continue

if isinstance(value, ObjectId):
ids.add(value)

elif isinstance(value, list):
if isinstance(value, list):
ids.update(value)

elif isinstance(value, dict):
ids.update(value.values())

else:
raise TypeError('Not a supported reference type')
ids.add(value)

# Find the referenced documents
ref = projection.pop('$ref')
Expand All @@ -592,11 +589,7 @@ def _dereference(cls, documents, references):
if not value:
continue

if isinstance(value, ObjectId):
# Single reference
value = frames.get(value, None)

elif isinstance(value, list):
if isinstance(value, list):
# List of references
value = [frames[id] for id in value if id in frames]

Expand All @@ -605,7 +598,7 @@ def _dereference(cls, documents, references):
value = {key: frames.get(id) for key, id in value.items()}

else:
raise TypeError('Not a supported reference type')
value = frames.get(value, None)

child_document = document
keys = cls._path_to_keys(path)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.0.2',
version='1.0.3',

description='A fast unobtrusive MongoDB ODM for Python',
long_description=long_description,
Expand Down

0 comments on commit e7dd67c

Please sign in to comment.