Is get_or_create() thread safe

Viewed 8951

I have a Django model that can only be accessed using get_or_create(session=session), where session is a foreign key to another Django model.

Since I am only accessing through get_or_create(), I would imagine that I would only ever have one instance with a key to the session. However, I have found multiple instances with keys to the same session. What is happening? Is this a race condition, or does get_or_create() operate atomically?

4 Answers
Related