Skip to content

Commit

Permalink
Fixes cascading saves with filefields
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza committed Jun 18, 2012
1 parent e4bc922 commit 89a6eee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

Changes in 0.6.X
================
- Fixed recursive save with FileField

Changes in 0.6.10
=================
- Fixed basedict / baselist to return super(..)
Expand Down
7 changes: 7 additions & 0 deletions mongoengine/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,13 @@ def __getstate__(self):
self_dict['_fs'] = None
return self_dict

def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.grid_id)

def __cmp__(self, other):
return cmp((self.grid_id, self.collection_name, self.db_alias),
(other.grid_id, other.collection_name, other.db_alias))

@property
def fs(self):
if not self._fs:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ def test_save_max_recursion_not_hit_with_file_field(self):

class Foo(Document):
name = StringField()
file = FileField()
picture = FileField()
bar = ReferenceField('self')

Foo.drop_collection()
Expand All @@ -1344,7 +1344,7 @@ class Foo(Document):
a.save()

a.bar = a
a.file = open(TEST_IMAGE_PATH, 'rb')
a.picture = open(TEST_IMAGE_PATH, 'rb')
a.save()

# Confirm can save and it resets the changed fields without hitting
Expand All @@ -1353,7 +1353,7 @@ class Foo(Document):
b.name='world'
b.save()

self.assertEquals(b.file, b.bar.file, b.bar.bar.file)
self.assertEquals(b.picture, b.bar.picture, b.bar.bar.picture)

def test_save_cascades(self):

Expand Down

0 comments on commit 89a6eee

Please sign in to comment.