From f7fbb3d2f6029f25aa294f9f49adcb7db3d1359b Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Tue, 20 Sep 2011 03:45:11 -0700 Subject: [PATCH] Relaxed field name checking on embedded documents --- mongoengine/base.py | 4 ++-- tests/document.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mongoengine/base.py b/mongoengine/base.py index c4bcee1e..02ad8bbf 100644 --- a/mongoengine/base.py +++ b/mongoengine/base.py @@ -391,7 +391,7 @@ class DocumentMetaclass(type): attrs['_db_field_map'] = dict([(k, v.db_field) for k, v in doc_fields.items() if k!=v.db_field]) attrs['_reverse_db_field_map'] = dict([(v, k) for k, v in attrs['_db_field_map'].items()]) - from mongoengine import Document + from mongoengine import Document, EmbeddedDocument new_class = super_new(cls, name, bases, attrs) for field in new_class._fields.values(): @@ -401,7 +401,7 @@ class DocumentMetaclass(type): field.document_type.register_delete_rule(new_class, field.name, delete_rule) - if field.name and hasattr(Document, field.name): + if field.name and hasattr(Document, field.name) and EmbeddedDocument not in new_class.mro(): raise InvalidDocumentError("%s is a document method and not a valid field name" % field.name) module = attrs.get('__module__') diff --git a/tests/document.py b/tests/document.py index 95f37748..1eeda46e 100644 --- a/tests/document.py +++ b/tests/document.py @@ -2336,7 +2336,7 @@ class DocumentTest(unittest.TestCase): pickle_doc.reload() self.assertEquals(resurrected, pickle_doc) - def throw_invalid_document_error(self): + def test_throw_invalid_document_error(self): # test handles people trying to upsert def throw_invalid_document_error():