Skip to content

Fix for fetching related information / dynamic immutable_lock_field #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2013
Merged

Conversation

Bouke
Copy link
Contributor

@Bouke Bouke commented Mar 12, 2013

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
Copy link
Contributor Author

Bouke commented Mar 12, 2013

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
Contributor

thanks Bouke!

@timdiggins
Copy link
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