red56/django-immutablemodel — pull request #1 by Bouke (2013-03-12 15:12:04+00:00)
Title: Fix for fetching related information / dynamic immutable_lock_field

In my project I've set immutable_lock_field to a @property, to have a dynamic locking mechanism. Django tries to store some cached relations when computing the immutable_lock_field, but it can't because all changes must be allowed by ImmutableModel. This results in a recursion, so I think ImmutableModel should always allow changing fields starting with `_`, as by Python conventions such variables should be considered private/protected.

immutablemodel/models.py in __setattr__
if not self.can_change_field(name): ...
immutablemodel/models.py in can_change_field
field_changable = field_name in self._meta.mutable_fields or not self.is_immutable() ...

▼ Local vars
Variable	Value
field_name	'_prefetched_objects_cache'

immutablemodel/models.py in is_immutable
return getattr(self, self._meta.immutable_lock_field, True) ...
(..)/models.py in @property field
return self.account.invoice and True ...
django/db/models/fields/related.py in __get__
setattr(instance, self.cache_name, rel_obj) ...
immutablemodel/models.py in __setattr__
if not self.can_change_field(name): ...