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

For TriggerVersionField, why is the the version manually incremented? #225

Open
bpartridge opened this issue Jul 31, 2021 · 0 comments
Open

Comments

@bpartridge
Copy link

Looking at:

@staticmethod
def _increment_version_number(obj):
old_value = get_revision_of_object(obj)
setattr(obj, obj._concurrencymeta.field.attname, int(old_value) + 1)
@staticmethod
def _wrap_model_methods(model):
super(TriggerVersionField, TriggerVersionField)._wrap_model_methods(model)
old_save = getattr(model, 'save')
setattr(model, 'save', model._concurrencymeta.field._wrap_save(old_save))
@staticmethod
def _wrap_save(func):
def inner(self, force_insert=False, force_update=False, using=None, **kwargs):
reload = kwargs.pop('refetch', False)
ret = func(self, force_insert, force_update, using, **kwargs)
TriggerVersionField._increment_version_number(self)

It appears that even if you're using a TriggerVersionField, the version is still incremented on the Python side on save. Wouldn't this cause an UPDATE, triggering the trigger, causing it to be incremented on the database (e.g. Postgres) side as well? Would this cause the effective version to increment by 2, rather than 1?

I suppose from a version comparison perspective, this isn't a huge problem; it would still satisfy the requirement that someone saving from the Django side compares the version they're editing to the version in the database, and if it's been increased at all, sound the alarms! But it seems like duplicative work, yea?

Is the reason perhaps because triggers might be uninstalled at any time, and it's just a safeguard to ensure that even if triggers go down the core Django functionality at least increments versions?

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

No branches or pull requests

1 participant