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

Already on GitHub? Sign in to your account

reload() fails for references where dbref=False #138

Closed
jakubroztocil opened this Issue Sep 20, 2012 · 3 comments

Comments

Projects
None yet
2 participants

Test case:

from mongoengine import connect, Document, ListField, ReferenceField

connect('test')

class Author(Document):
    meta = {
        'collection': 'authors',
        'allow_inheritance': False
    }

class Post(Document):
    authors = ListField(ReferenceField(Author, dbref=False))

author = Author()
author.save()

post = Post(authors=[author])
post.save()

post.reload() # => mongoengine.base.NotRegistered:

Traceback:

File "test.py", line 22, in <module>
     post.reload()
   File "mongoengine/mongoengine/document.py", line 364, in reload
     ).first().select_related(max_depth=max_depth)
   File "mongoengine/mongoengine/document.py", line 352, in select_related
     self._data = dereference.DeReference()(self._data, max_depth)
   File "mongoengine/mongoengine/dereference.py", line 64, in __call__
     self.object_map = self._fetch_objects(doc_type=doc_type)
   File "mongoengine/mongoengine/dereference.py", line 137, in _fetch_objects
     for x in col.split('_')))._from_son(ref)
   File "mongoengine/mongoengine/base.py", line 135, in get_document
     """.strip() % name)
 mongoengine.base.NotRegistered: `Authors` has not been registered in the document registry.
             Importing the document class automatically registers it, has it
             been imported?
Contributor

rozza commented Sep 21, 2012

Hi thanks for the ticket. I'm on the road at the moment and will address
this on Monday.

Ross

On Thursday, September 20, 2012, Jakub Roztocil wrote:

The problem is that meta['collection'] is not honoured.

Test case:

from mongoengine import connect, Document, ListField, ReferenceField

connect('test')

class Author(Document):
meta = {
'collection': 'authors',
'allow_inheritance': False
}

class Post(Document):
authors = ListField(ReferenceField(Author, dbref=False))

author = Author()
author.save()

post = Post(authors=[author])
post.save()

post.reload() # => mongoengine.base.NotRegistered:

Traceback:

File "test.py", line 22, in
post.reload()
File "mongoengine/mongoengine/document.py", line 364, in reload
).first().select_related(max_depth=max_depth)
File "mongoengine/mongoengine/document.py", line 352, in select_related
self._data = dereference.DeReference()(self._data, max_depth)
File "mongoengine/mongoengine/dereference.py", line 64, in call
self.object_map = self._fetch_objects(doc_type=doc_type)
File "mongoengine/mongoengine/dereference.py", line 137, in fetch_objects
for x in col.split('
')))._from_son(ref)
File "mongoengine/mongoengine/base.py", line 135, in get_document
""".strip() % name)
mongoengine.base.NotRegistered: Authors has not been registered in the document registry.
Importing the document class automatically registers it, has it
been imported?


Reply to this email directly or view it on GitHubhttps://github.com/MongoEngine/mongoengine/issues/138.

Contributor

rozza commented Sep 24, 2012

@jkbr thanks for the ticket - tricky one to nail that one - but fixed in the 0.7 branch

@rozza rozza closed this Sep 24, 2012

Awesome, thanks! 🍰

samuelclay added a commit to samuelclay/mongoengine that referenced this issue Oct 29, 2012

Merge branch 'master' of https://github.com/MongoEngine/mongoengine
* 'master' of https://github.com/MongoEngine/mongoengine: (24 commits)
  Fixing py3 compat
  Added chaining regression test (MongoEngine/mongoengine#135)
  Updated test
  Unicode fix for repr (MongoEngine/mongoengine#133)
  Allow updates with match operators (MongoEngine/mongoengine#144)
  Unicode fix reverted but can have custom validator
  Fix loop
  Updated URLField
  Added Garry Polley to contributors list
  can now use AuthenticationBackends with permissions.
  Updates to the readme
  Added CONTRIBUTING.rst
  Updated docs thanks @mitar
  Moved injection of Exceptions to top level
  Fixed reload issue with ReferenceField where dbref=False (MongoEngine/mongoengine#138)
  Improved import cache
  Fixed objectId for DBRef
  Updated travis.yml
  Fix ReferenceField dbref = False
  Updated docs
  ...

samuelclay added a commit to samuelclay/mongoengine that referenced this issue Jan 28, 2013

Merge branch 'master' of github.com:samuelclay/mongoengine
* 'master' of github.com:samuelclay/mongoengine: (227 commits)
  Adding QuerySet(read_preference=pymongo.ReadPreference.X) and QuerySet().read_preference() method to override connection-level read_preference on a per-query basis.
  Fixing py3 compat
  Added chaining regression test (MongoEngine/mongoengine#135)
  Updated test
  Unicode fix for repr (MongoEngine/mongoengine#133)
  Allow updates with match operators (MongoEngine/mongoengine#144)
  Unicode fix reverted but can have custom validator
  Fix loop
  Updated URLField
  Added Garry Polley to contributors list
  can now use AuthenticationBackends with permissions.
  Updates to the readme
  Added CONTRIBUTING.rst
  Updated docs thanks @mitar
  Moved injection of Exceptions to top level
  Fixed reload issue with ReferenceField where dbref=False (MongoEngine/mongoengine#138)
  Improved import cache
  Fixed objectId for DBRef
  Updated travis.yml
  Fix ReferenceField dbref = False
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment