File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
ansible_base/resource_registry/models Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 22import uuid
33
44from django .conf import settings
5- from django .db import models
5+ from django .db import IntegrityError , models , transaction
66
77
88class ServiceID (models .Model ):
@@ -27,8 +27,13 @@ def service_id():
2727 if not _service_id :
2828 obj = ServiceID .objects .first ()
2929 if obj is None :
30- if settings .DEBUG or any ("pytest" in arg for arg in sys .argv ):
31- obj = ServiceID .objects .create ()
30+ if settings .DEBUG or "pytest" in sys .argv :
31+ try :
32+ with transaction .atomic ():
33+ obj = ServiceID .objects .create (pk = 1 )
34+ except IntegrityError :
35+ # Another thread/process won the race—read it
36+ obj = ServiceID .objects .get (pk = 1 )
3237 else :
3338 raise RuntimeError ('Expected ServiceID to be created in data migrations but was not found' )
3439 _service_id = str (obj .pk )
You can’t perform that action at this time.
0 commit comments