Skip to content

Fix for fetching related information / dynamic immutable_lock_field - #1

Merged
timdiggins merged 2 commits into
red56:masterfrom
Bouke:patch-1
Mar 12, 2013
Merged

Fix for fetching related information / dynamic immutable_lock_field#1
timdiggins merged 2 commits into
red56:masterfrom
Bouke:patch-1

Conversation

@Bouke

@Bouke Bouke commented Mar 12, 2013

Copy link
Copy Markdown
Contributor

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): ...

@Bouke

Bouke commented Mar 12, 2013

Copy link
Copy Markdown
Contributor Author

Tests seem fine:

Ran 27 tests in 0.121s

timdiggins added a commit that referenced this pull request Mar 12, 2013
Fix for fetching related information / dynamic immutable_lock_field
ignores immutability for fields beginning with _
@timdiggins
timdiggins merged commit 5c9d3a7 into red56:master Mar 12, 2013
@timdiggins

Copy link
Copy Markdown
Contributor

thanks Bouke!

@timdiggins

Copy link
Copy Markdown
Contributor

released as 0.3.4 with tests and docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants