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

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

Closed
jkbrzt opened this issue Sep 20, 2012 · 3 comments
Closed

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

jkbrzt opened this issue Sep 20, 2012 · 3 comments

Comments

@jkbrzt
Copy link

jkbrzt commented Sep 20, 2012

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?
@rozza
Copy link
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//issues/138.

@rozza
Copy link
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 as completed Sep 24, 2012
@jkbrzt
Copy link
Author

jkbrzt commented Sep 28, 2012

Awesome, thanks! 🍰

samuelclay added a commit to samuelclay/mongoengine that referenced this issue Oct 29, 2012
* 'master' of https://github.com/MongoEngine/mongoengine: (24 commits)
  Fixing py3 compat
  Added chaining regression test (MongoEngine#135)
  Updated test
  Unicode fix for repr (MongoEngine#133)
  Allow updates with match operators (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#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
* '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#135)
  Updated test
  Unicode fix for repr (MongoEngine#133)
  Allow updates with match operators (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#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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants