﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24009	get_or_create can raise an IntegrityError in race conditions	Mihail Milushev	nobody	"`get_or_create` is described as being atomic in the documentation, but that is not the case. Since it first tries to retrieve an existing record and if that fails it tries to create a new one, another thread can create that record in the small interval between the two operations. This will not result in data corruption as the database will enforce its constraints, but it makes the whole convenience method not that convenient, if I also need to handle this in a `try` block around its invocation. If I _need_ to do `try: get_or_create() except IntegrityError: get()` anyway, it makes no sense to use `get_or_create` in the first place, that logic would work if I just try to create the entity and only retrieve it if the create raises an `IntegrityError`.

When I call `get_or_create` I expect it to return the existing record, or to create a new record if one does not exist yet. Getting an `IntegrityError` there is like saying ""there's no existing record, but I cannot create a new one because one already exists""."	Uncategorized	closed	Uncategorized	1.7	Normal	needsinfo			Unreviewed	0	0	0	0	0	0
