django-concurrency icon indicating copy to clipboard operation
django-concurrency copied to clipboard

For TriggerVersionField, why is the the version manually incremented?

Open bpartridge opened this issue 4 years ago • 0 comments

Looking at:

https://github.com/saxix/django-concurrency/blob/ff8eecf9198cefba9ad411371efe1fc30d796d3c/src/concurrency/fields.py#L260-L276

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?

bpartridge avatar Jul 31 '21 15:07 bpartridge