Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Don't raise errors when loading old objects from fixtures #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions versions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
def get_utc_now():
return datetime.datetime.utcnow().replace(tzinfo=utc)

def running_in_deserializer():
import traceback
for path, line_no, function_name, code_line in reversed(traceback.extract_stack()):
if path.endswith('django/core/serializers/base.py'):
return True

return False

QueryTime = namedtuple('QueryTime', 'time active')

Expand Down Expand Up @@ -865,7 +872,7 @@ def _remove_items_at(self, timestamp, source_field_name, target_field_name, *obj

if 'add' in dir(many_related_manager_klass):
def add(self, *objs):
if not self.instance.is_current:
if not self.instance.is_current and not running_in_deserializer():
raise SuspiciousOperation(
"Adding many-to-many related objects is only possible on the current version")

Expand Down Expand Up @@ -958,7 +965,7 @@ def __set__(self, instance, value):
:param value: iterable of items to set
"""

if not instance.is_current:
if not instance.is_current and not running_in_deserializer():
raise SuspiciousOperation(
"Related values can only be directly set on the current version of an object")

Expand Down