Skip to content
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

Cross-instance issues for ConditionalVersionField #254

Open
kevinmsun opened this issue Feb 24, 2025 · 3 comments
Open

Cross-instance issues for ConditionalVersionField #254

kevinmsun opened this issue Feb 24, 2025 · 3 comments

Comments

@kevinmsun
Copy link

kevinmsun commented Feb 24, 2025

I'm using ConditionalVersionField for a model, specifically with ignore_fields configured in my ConcurrencyMeta. I'm finding that, when multiple instances of the class are loaded simultaneously, the initial is being shared/overwritten rather than being uniquely maintained per instance, thus leading to significantly more version bumps (and RecordModifiedErrors) than expected

In my observations, the models are loaded and the initial is recorded in _concurrencymeta at

instance._concurrencymeta.initial = self._get_hash(instance)
. However, the ._concurrencymeta actually appears to be shared across all my instances, meaning that each loaded instance overwrites the recorded initial value for preceding instances. When it's consulted to check for changes (
old = model_instance._concurrencymeta.initial
new = self._get_hash(model_instance)
if old != new:
return int(getattr(model_instance, self.attname, 0) + 1)
), it "always" returns an incremented value (unless I happen to be operating on the last instance loaded).

@saxix
Copy link
Owner

saxix commented Feb 25, 2025

@kevinmsun I see the point, and it seems this is a bug. You are right when you say that _concurrencymeta is shared because it is a class attribute

We need to change the line you pointed out as

instance._concurrencymeta_initial = self._get_hash(instance) 

and change the three places where it is used.

I do not have the time to work on this right now, but I'll be happy to get a PR if you want.

@kevinmsun
Copy link
Author

@saxix thanks for the information/review.

What's the recommended process to contribute? I tried pushing a branch in order to open a PR, but was denied access; do you recommend forking or something like that?

@saxix
Copy link
Owner

saxix commented Feb 26, 2025

@kevinmsun, you can fork the repo and make a pr from your repo in github. You can use the same process as described here https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/working-with-git/

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

No branches or pull requests

2 participants