From 5d8ffded40a53a884093a034f2f0dc99662904aa Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Sat, 23 Jun 2012 22:19:02 +0100 Subject: [PATCH] Fixed issue with embedded_docs and db_fields Bumped version also refs: hmarr/mongoengine#523 --- docs/changelog.rst | 3 ++- mongoengine/__init__.py | 2 +- mongoengine/base.py | 2 ++ python-mongoengine.spec | 2 +- tests/test_document.py | 16 ++++++++++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 6272aecd..e0f497cd 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,8 +2,9 @@ Changelog ========= -Changes in 0.6.X +Changes in 0.6.13 ================ +- Fixed EmbeddedDocument db_field validation issue - Fixed StringField unicode issue - Fixes __repr__ modifying the cursor diff --git a/mongoengine/__init__.py b/mongoengine/__init__.py index 1d65826e..80a687c8 100644 --- a/mongoengine/__init__.py +++ b/mongoengine/__init__.py @@ -12,7 +12,7 @@ from signals import * __all__ = (document.__all__ + fields.__all__ + connection.__all__ + queryset.__all__ + signals.__all__) -VERSION = (0, 6, 12) +VERSION = (0, 6, 13) def get_version(): diff --git a/mongoengine/base.py b/mongoengine/base.py index a4c1599c..8ed8dc40 100644 --- a/mongoengine/base.py +++ b/mongoengine/base.py @@ -957,6 +957,8 @@ class BaseDocument(object): try: data[field_name] = (value if value is None else field.to_python(value)) + if field_name != field.db_field: + del data[field.db_field] except (AttributeError, ValueError), e: errors_dict[field_name] = e elif field.default: diff --git a/python-mongoengine.spec b/python-mongoengine.spec index 6a78e9b0..c3919f1f 100644 --- a/python-mongoengine.spec +++ b/python-mongoengine.spec @@ -5,7 +5,7 @@ %define srcname mongoengine Name: python-%{srcname} -Version: 0.6.12 +Version: 0.6.13 Release: 1%{?dist} Summary: A Python Document-Object Mapper for working with MongoDB diff --git a/tests/test_document.py b/tests/test_document.py index 2b10c172..482a502d 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -1282,6 +1282,22 @@ class DocumentTest(unittest.TestCase): comment.date = datetime.now() comment.validate() + def test_embedded_db_field_validate(self): + + class SubDoc(EmbeddedDocument): + val = IntField() + + class Doc(Document): + e = EmbeddedDocumentField(SubDoc, db_field='eb') + + Doc.drop_collection() + + Doc(e=SubDoc(val=15)).save() + + doc = Doc.objects.first() + doc.validate() + self.assertEquals([None, 'e'], doc._data.keys()) + def test_save(self): """Ensure that a document may be saved in the database. """