Update documentation for race-condition in analytics._update_counter
@@ -25,6 +25,8 @@ def _update_counter(model, field_name, filter_kwargs, increment=1):
Efficiently updates a counter field by a given increment. Uses Django's
update() call to fetch and update in one query.
+ TODO: This has a race condition, we should use UPSERT here
+
:param model: The model class of the recording model
:param field_name: The name of the field to update
:param filter_kwargs: Parameters to the ORM's filter() function to get the
@@ -37,8 +39,8 @@ def _update_counter(model, field_name, filter_kwargs, increment=1):
filter_kwargs[field_name] = increment
model.objects.create(**filter_kwargs)
except IntegrityError:
- # get_or_create sometimes fails due to MySQL's weird transactions, fail
- # silently
+ # get_or_create has a race condition (we should use upsert in supported)
+ # databases. For now just ignore these errors
logger.error(
"IntegrityError when updating analytics counter for %s", model)
