We are using Python 3.5, Django 1.10 and PostgreSql 9.6 DB
We needed some Auto-increment field for one of the object (Item), and couldn't achieve that using DB auto increment, since there is another dependency for the incrementation.
The field should be incremented for Item per Project (each Project can contain multiple items).
We decided to use django-sequences package that basically creates another table (we're using the same DB as our models), and increments the field whenever asked to by locking the DB and increment the highest value according to relevant parameter (in our case the Project id). Seems like it works.
The problem occurs when there are multiple requests in parallel. Seems like the DB gets locked and we're starting to get 504 after few requests.
Why it happens and what could solve that?
This is the django-sequences use:
if instance.identifier < 0:
with transaction.atomic():
instance.identifier = get_next_value(
'project__' + str(instance.project.id) + '__item__identifier',
initial_value=1,
nowait=False
)
Update: Seems like the 504 come from Apigee which is set to Timeout of 10 sec.