Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed db_field load error

  • Loading branch information...
commit 9e7ea64bd2cc4b42494b574750ff2afa5e8237b8 1 parent 89a6eee
@rozza rozza authored
View
2  .gitignore
@@ -13,5 +13,5 @@ env/
.settings
.project
.pydevproject
-tests/bugfix.py
+tests/test_bugfix.py
htmlcov/
View
1  docs/changelog.rst
@@ -4,6 +4,7 @@ Changelog
Changes in 0.6.X
================
+- Fixed db_field data load error
- Fixed recursive save with FileField
Changes in 0.6.10
View
1  mongoengine/base.py
@@ -798,6 +798,7 @@ def __init__(self, **values):
dynamic_data[key] = value
else:
for key, value in values.items():
+ key = self._reverse_db_field_map.get(key, key)
setattr(self, key, value)
# Set any get_fieldname_display methods
View
47 tests/test_bugfix.py
@@ -1,47 +0,0 @@
-# import pickle
-# import pymongo
-# import bson
-# import warnings
-
-# from datetime import datetime
-
-# import tempfile
-# import pymongo, gridfs
-
-import unittest
-from mongoengine import *
-from bson.objectid import ObjectId
-
-class BugFixTest(unittest.TestCase):
-
-
- def setUp(self):
-
- conn = connect(db='mongoenginetest')
-
- def test_items_list(self):
-
- class ActivityType1(EmbeddedDocument):
- activity_id = IntField()
- activity_name = StringField()
-
- class ActivityType2(EmbeddedDocument):
- activity_id = IntField()
- activity_status = StringField()
-
- class UserActivities(Document):
- user_id = IntField()
- activity = GenericEmbeddedDocumentField(choices=(ActivityType1, ActivityType2))
-
-
- UserActivities.drop_collection()
-
- user_id = 123
- activity_id = 321
- UserActivities(user_id=user_id, activity=ActivityType2(activity_id=activity_id, activity_status="A")).save()
-
- self.assertEquals(1, UserActivities.objects(user_id=user_id, __raw__={'activity.activity_status': 'A'}).count())
-
-
-
-
View
20 tests/test_document.py
@@ -664,6 +664,26 @@ class ExtendedBlogPost(BlogPost):
BlogPost.drop_collection()
+ def test_db_field_load(self):
+ """Ensure we load data correctly
+ """
+ class Person(Document):
+ name = StringField(required=True)
+ _rank = StringField(required=False, db_field="rank")
+
+ @property
+ def rank(self):
+ return self._rank or "Private"
+
+ Person.drop_collection()
+
+ Person(name="Jack", _rank="Corporal").save()
+
+ Person(name="Fred").save()
+
+ self.assertEquals(Person.objects.get(name="Jack").rank, "Corporal")
+ self.assertEquals(Person.objects.get(name="Fred").rank, "Private")
+
def test_explicit_geo2d_index(self):
"""Ensure that geo2d indexes work when created via meta[indexes]
"""
Please sign in to comment.
Something went wrong with that request. Please try again.