Wednesday, November 23, 2022

getting unique id

I have an app that needs to get a unique ID. Many threads run at the
same time that need one. I would like the IDs to be sequential. When I
need a unique ID I do this:

with transaction.atomic():
max_batch_id =
json_dict['batch_id'] = max_batch_id['batch_id__max'] + 1
status_row = JobStatus(**json_dict)

But multiple jobs are getting the same ID. Why does the code not work
as I expect? What is a better way to accomplish what I need?

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

No comments:

Post a Comment