Skip to content

Commit

Permalink
fixup! add test for broken code, will result in:
Browse files Browse the repository at this point in the history
File "/home/jens/PyLucid_env/src/django-reversion-
compare/reversion_compare/admin.py", line 105, in get_related
    if hasattr(obj, self.field.name):
File "/home/jens/PyLucid_env/lib/python3.4/site-
packages/django/db/models/fields/related.py", line 572, in __get__
    rel_obj = qs.get()
File "/home/jens/PyLucid_env/lib/python3.4/site-
packages/django/db/models/query.py", line 357, in get
    self.model._meta.object_name)
tests.models.DoesNotExist: Factory matching query does not exist.

See also:
38f03aa#diff-92a7865015c98ad7c63bd568db5e5906R106
  • Loading branch information
jedie committed Jul 23, 2015
1 parent ba22008 commit 0e7fe4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.creole
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ Maybe other versions are compatible, too.

== changelog ==

* **dev**
** Bugfix if old related object was deleted
* [[https://github.com/jedie/django-reversion-compare/compare/v0.5.3...v0.5.4|v0.5.4 - 22.07.2015]]:
** One to one field custom related name fix [[https://github.com/jedie/django-reversion-compare/pull/42|#42]] (contributed by frwickst and aemdy)
* [[https://github.com/jedie/django-reversion-compare/compare/v0.5.2...v0.5.3|v0.5.3 - 13.07.2015]]:
Expand Down
4 changes: 3 additions & 1 deletion reversion_compare/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ def __ne__(self, other):
def get_related(self):
if getattr(self.field, 'rel', None):
obj = self.version.object_version.object
if hasattr(obj, self.field.name):
try:
return getattr(obj, self.field.name, None)
except ObjectDoesNotExist:
return None

def get_reverse_foreign_key(self):
obj = self.version.object_version.object
Expand Down
7 changes: 6 additions & 1 deletion tests/test_factory_car_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ def test_initial_state(self):
self.assertEqual(Version.objects.all().count(), 0)

def test_deleted_objects(self):
"""
for:
https://github.com/jedie/django-reversion-compare/commit/ba22008130f4c16a32eeb900381c2d82ca6fdd9e
https://travis-ci.org/jedie/django-reversion-compare/builds/72317520
"""
with reversion.create_revision():
factory1 = Factory.objects.create(name="factory one")
car = Car.objects.create(
Expand All @@ -180,4 +185,4 @@ def test_deleted_objects(self):
"/admin/tests/car/%s/history/compare/" % car.pk,
data={"version_id2":version_ids[0], "version_id1":version_ids[1]}
)
debug_response(response) # from django-tools
# debug_response(response) # from django-tools

0 comments on commit 0e7fe4d

Please sign in to comment.