Skip to content

Conversation

@paularmand
Copy link
Contributor

The following throws an error:

import pymongo as pm
import mongoengine as me
import pprint


db_name = "test_database"
collection_name = "post"
collection_name_items = "post_items"

# get collections through pymongo
client = pm.MongoClient()
db = client[db_name]

# insert a reference document
posts = db[collection_name]
post = {"title": "Lunar eclipse", "body": "lorum ipsim and the rest"}
posts.insert_one(post)

# insert the test document
posts_items = db[collection_name_items]
post_items = {"title": "Items eclipse", "body": "lorum ipsim and the rest", "items": ["more lorem", "even more ipsum"]}
posts_items.insert_one(post_items)


class Post(me.Document):
    meta = {
        'strict': False
    }
    title = me.StringField(required=True, max_length=200)
    body = me.StringField(required=True, max_length=2000)


class PostItems(me.Document):
    meta = {
        'strict': False
    }
    title = me.StringField(required=True, max_length=200)
    body = me.StringField(required=True, max_length=2000)
    items = me.StringField()

me.connect(db_name, alias="default")
post_retrieved = Post.objects().first()
pprint.pprint(post_retrieved)

post_items_retrieved = PostItems.objects().first()
pprint.pprint(post_items_retrieved)
print("should print items")
print post_items_retrieved.items

post_items_retrieved.reload()
print post_items_retrieved.items

the trace:

Traceback (most recent call last):
  File "test.py", line 49, in <module>
    post_items_retrieved.reload()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/document.py", line 606, in reload
    delattr(self, field)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mongoengine/base/document.py", line 145, in __delattr__
    super(BaseDocument, self).__delattr__(*args, **kwargs)
AttributeError: _reserved_items

The pull request is resolves the issue by trying to get the field _reserved_items from _data as a fallback.

If you give an indication as to where (in which test class) I need to write the nose test for this issue, I'll do that. On my local platform python setup.py nosetests gives

742 tests run in 32.2 seconds. 
4 skipped (738 tests passed)

Review on Reviewable

@paularmand
Copy link
Contributor Author

I've added issue #1156 to the changelog and myself to the contributors list as you suggested.

@paularmand
Copy link
Contributor Author

Thanks, and I've added a test as per your request in the document tests.

@paularmand
Copy link
Contributor Author

And resolved the merge conflict in AUTHORS.

@thedrow thedrow merged commit 6133f04 into MongoEngine:master Nov 30, 2015
@paularmand paularmand deleted the fix-reloading-strict branch November 30, 2015 20:47
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

Successfully merging this pull request may close these issues.

1 participant