MongoEngine/mongoengine — pull request #374 by ygbourhis (2013-06-19 09:24:44+00:00)
Title: test_validation_after_reload unittest

Hi, I fell on a `ReferenceError: weakly-referenced object no longer exists` in mongoengine 0.8.2, so I added a unittest which reproduces the error (in order to help fixing):

```
$ python setup.py test --test-suite tests.document.validation.ValidatorErrorTest.test_validation_after_reload
0.8.2
running test
running egg_info
writing requirements to mongoengine.egg-info/requires.txt
writing mongoengine.egg-info/PKG-INFO
writing top-level names to mongoengine.egg-info/top_level.txt
writing dependency_links to mongoengine.egg-info/dependency_links.txt
reading manifest file 'mongoengine.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'docs/_build'
writing manifest file 'mongoengine.egg-info/SOURCES.txt'
running build_ext
test_validation_after_reload (tests.document.validation.ValidatorErrorTest) ... ERROR

======================================================================
ERROR: test_validation_after_reload (tests.document.validation.ValidatorErrorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ygbourhis/Dev/ygbourhis/mongoengine/tests/document/validation.py", line 168, in test_validation_after_reload
doc.save()
File "mongoengine/document.py", line 223, in save
self.validate(clean=clean)
File "mongoengine/base/document.py", line 306, in validate
field._validate(value, clean=clean)
File "mongoengine/base/fields.py", line 175, in _validate
self.validate(value, **kwargs)
File "mongoengine/fields.py", line 563, in validate
self.document_type.validate(value, clean)
File "mongoengine/base/document.py", line 321, in validate
elif self._instance:
ReferenceError: weakly-referenced object no longer exists

----------------------------------------------------------------------
Ran 1 test in 0.007s

FAILED (errors=1)
```

Thanks.