_get_changed_fields fix for embedded documents with id field.

removed commented out piece of code

added author and record to changelog
This commit is contained in:
Eremeev Danil 2015-04-01 10:10:08 +05:00
parent 103a287f11
commit f77f45b70c
4 changed files with 6 additions and 2 deletions

View File

@ -219,3 +219,4 @@ that much better:
* Jimmy Shen (https://github.com/jimmyshen) * Jimmy Shen (https://github.com/jimmyshen)
* J. Fernando Sánchez (https://github.com/balkian) * J. Fernando Sánchez (https://github.com/balkian)
* Michael Chase (https://github.com/rxsegrxup) * Michael Chase (https://github.com/rxsegrxup)
* Eremeev Danil (https://github.com/elephanter)

View File

@ -85,6 +85,7 @@ Changes in 0.9.0
- Fixed a few instances where reverse_delete_rule was written as reverse_delete_rules. #791 - Fixed a few instances where reverse_delete_rule was written as reverse_delete_rules. #791
- Make `in_bulk()` respect `no_dereference()` #775 - Make `in_bulk()` respect `no_dereference()` #775
- Handle None from model __str__; Fixes #753 #754 - Handle None from model __str__; Fixes #753 #754
- _get_changed_fields fix for embedded documents with id field. #925
Changes in 0.8.7 Changes in 0.8.7
================ ================

View File

@ -308,7 +308,7 @@ class BaseDocument(object):
""" """
if not fields: if not fields:
fields = [] fields = []
data = SON() data = SON()
data["_id"] = None data["_id"] = None
data['_cls'] = self._class_name data['_cls'] = self._class_name
@ -553,7 +553,6 @@ class BaseDocument(object):
if hasattr(data, 'id'): if hasattr(data, 'id'):
if data.id in inspected: if data.id in inspected:
continue continue
inspected.add(data.id)
if isinstance(field, ReferenceField): if isinstance(field, ReferenceField):
continue continue
elif (isinstance(data, (EmbeddedDocument, DynamicEmbeddedDocument)) elif (isinstance(data, (EmbeddedDocument, DynamicEmbeddedDocument))

View File

@ -93,6 +93,7 @@ class DeltaTest(unittest.TestCase):
def delta_recursive(self, DocClass, EmbeddedClass): def delta_recursive(self, DocClass, EmbeddedClass):
class Embedded(EmbeddedClass): class Embedded(EmbeddedClass):
id = StringField()
string_field = StringField() string_field = StringField()
int_field = IntField() int_field = IntField()
dict_field = DictField() dict_field = DictField()
@ -114,6 +115,7 @@ class DeltaTest(unittest.TestCase):
self.assertEqual(doc._delta(), ({}, {})) self.assertEqual(doc._delta(), ({}, {}))
embedded_1 = Embedded() embedded_1 = Embedded()
embedded_1.id = "010101"
embedded_1.string_field = 'hello' embedded_1.string_field = 'hello'
embedded_1.int_field = 1 embedded_1.int_field = 1
embedded_1.dict_field = {'hello': 'world'} embedded_1.dict_field = {'hello': 'world'}
@ -123,6 +125,7 @@ class DeltaTest(unittest.TestCase):
self.assertEqual(doc._get_changed_fields(), ['embedded_field']) self.assertEqual(doc._get_changed_fields(), ['embedded_field'])
embedded_delta = { embedded_delta = {
'id': "010101",
'string_field': 'hello', 'string_field': 'hello',
'int_field': 1, 'int_field': 1,
'dict_field': {'hello': 'world'}, 'dict_field': {'hello': 'world'},