Preventing race conditions when updating JSONField

Having read this article today, Denormalization with JSON Fields for a Performance Boost, I got to wondering how to something like an F() expression to avoid race conditions might work to prevent having to increment a value in Python instead of the DB as the example shown in the post’s method.

It seems that F() expressions do not work here so is there a way to have these kinds of operations done in the DB level inside of a JSONField without using F() expressions?


Edit: One person’s method for doing this: Django’s JSONField incrementation with F expressions

You also have the ability to create your own query expression. (I don’t know what that would look like in this case, but it is an option.)

1 Like

Django 4.2 introduces KT() expressions, which I also tried to use for this purpose, but I wasn’t able to get anything working.