Permalink
Browse files

Fixed an important issue in _pre_save, that prevents loading fixtures…

… of models that are registered for translation.

Or more generally, saving new records with pk specified.
  • Loading branch information...
botondus authored and gvangool committed Jul 1, 2010
1 parent d588c49 commit fc8b413985f01374fd8594ea8adf568cc6332f39
Showing with 8 additions and 2 deletions.
  1. +8 −2 datatrans/utils.py
View
@@ -1,5 +1,5 @@
from django.conf import settings
-from django.core.exceptions import ImproperlyConfigured
+from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.db import models
from django.utils import translation
from django.utils.datastructures import SortedDict
@@ -85,9 +85,15 @@ def _pre_save(sender, instance, **kwargs):
# When we edit a registered model, update the original translations and mark them as unedited (to do)
if instance.pk is not None:
+ try:
+ # Just because instance.pk is set, it does not mean that the instance
+ # is saved. Most typical/important ex: loading fixtures
+ original = sender.objects.get(pk=instance.pk)
+ except ObjectDoesNotExist:
+ return None
+
register = get_registry()
fields = register[sender].values()
- original = sender.objects.get(pk=instance.pk)
for field in fields:
old_digest = make_digest(original.__dict__[field.name])
new_digest = make_digest(instance.__dict__[field.name])

0 comments on commit fc8b413

Please sign in to comment.