From bab186e1950de5902c914f8746f706802e31dfeb Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Mon, 14 May 2012 12:02:07 +0100 Subject: [PATCH] Reverted document.delete auto gridfs delete --- docs/changelog.rst | 4 ++++ docs/guide/gridfs.rst | 9 +++++---- mongoengine/base.py | 5 ----- mongoengine/document.py | 12 ------------ tests/fields.py | 32 -------------------------------- 5 files changed, 9 insertions(+), 53 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 3231084b7..44ae826e0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,10 @@ Changelog ========= +Changes in 0.6.9 +================ +- Removed FileField auto deletion, needs more work maybe 0.7 + Changes in 0.6.8 ================ - Fixed FileField losing reference when no default set diff --git a/docs/guide/gridfs.rst b/docs/guide/gridfs.rst index 695a0be08..9c80a99ea 100644 --- a/docs/guide/gridfs.rst +++ b/docs/guide/gridfs.rst @@ -65,12 +65,13 @@ Deleting stored files is achieved with the :func:`delete` method:: marmot.photo.delete() -.. note:: +.. warning:: The FileField in a Document actually only stores the ID of a file in a - separate GridFS collection. This means that `Animal.drop_collection()` will - not delete any files. Care should be taken to manually remove associated - files before dropping a collection. + separate GridFS collection. This means that deleting a document + with a defined FileField does not actually delete the file. You must be + careful to delete any files in a Document as above before deleting the + Document itself. Replacing files diff --git a/mongoengine/base.py b/mongoengine/base.py index 347332b28..ec7af4532 100644 --- a/mongoengine/base.py +++ b/mongoengine/base.py @@ -618,10 +618,6 @@ def _get_mixin_fields(base): raise InvalidDocumentError("Reverse delete rules are not supported for EmbeddedDocuments (field: %s)" % field.name) f.document_type.register_delete_rule(new_class, field.name, delete_rule) - proxy_class = getattr(field, 'proxy_class', None) - if proxy_class is not None: - new_class.register_proxy_field(field.name, proxy_class) - 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) @@ -723,7 +719,6 @@ def __new__(cls, name, bases, attrs): 'index_opts': {}, 'queryset_class': QuerySet, 'delete_rules': {}, - 'proxy_fields': {}, 'allow_inheritance': True } diff --git a/mongoengine/document.py b/mongoengine/document.py index 7f33812c5..9e281f5c5 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -278,11 +278,6 @@ def delete(self, safe=False): signals.pre_delete.send(self.__class__, document=self) try: - for field_name in self._meta['proxy_fields']: - proxy_class = self._meta['proxy_fields'][field_name] - if hasattr(proxy_class, 'delete'): - proxy = getattr(self, field_name) - proxy.delete() self.__class__.objects(pk=self.pk).delete(safe=safe) except pymongo.errors.OperationFailure, err: message = u'Could not delete document (%s)' % err.message @@ -347,13 +342,6 @@ def register_delete_rule(cls, document_cls, field_name, rule): """ cls._meta['delete_rules'][(document_cls, field_name)] = rule - @classmethod - def register_proxy_field(cls, field_name, proxy_class): - """This method registers fields with proxy classes to delete them when - removing this object. - """ - cls._meta['proxy_fields'][field_name] = proxy_class - @classmethod def drop_collection(cls): """Drops the entire collection associated with this diff --git a/tests/fields.py b/tests/fields.py index b75ef0a8a..85f291195 100644 --- a/tests/fields.py +++ b/tests/fields.py @@ -1620,38 +1620,6 @@ class DemoFile(Document): file = FileField() DemoFile.objects.create() - def test_file_delete_cleanup(self): - """Ensure that the gridfs file is deleted when a document - with a GridFSProxied Field is deleted""" - class TestFile(Document): - file = FileField() - - class TestImage(Document): - image = ImageField() - - TestFile.drop_collection() - - testfile = TestFile() - testfile.file.put('Hello, World!') - testfile.save() - - testfile_grid_id = testfile.file.grid_id - testfile_fs = testfile.file.fs - - testfile.delete() - self.assertFalse(testfile_fs.exists(testfile_grid_id)) - - TestImage.drop_collection() - - testimage = TestImage() - testimage.image.put(open(TEST_IMAGE_PATH, 'r')) - testimage.save() - - testimage_grid_id = testimage.image.grid_id - testimage_fs = testimage.image.fs - - testimage.delete() - self.assertFalse(testimage_fs.exists(testimage_grid_id)) def test_file_field_no_default(self):