Avoid Project..get_or_create() in create_preload_data

Django ORM method get_or_create() does not call save() directly,
but it calls the create() [1].

The create method ignores the skip_update=True option, which then
will trigger a project update, however the EE was not yet created
in the database.

To avoid this problem, we just check the existence of the default
project and creates it with save(skip_update=True) manually.
This commit is contained in:
Marcelo Moreira de Mello
2022-01-24 17:16:15 -05:00
parent 85cc67fb4e
commit 7ae6286152

View File

@@ -25,13 +25,17 @@ class Command(BaseCommand):
if not Organization.objects.exists(): if not Organization.objects.exists():
o, _ = Organization.objects.get_or_create(name='Default') o, _ = Organization.objects.get_or_create(name='Default')
p, _ = Project.objects.get_or_create( # Avoid calling directly the get_or_create() to bypass project update
name='Demo Project', p = Project.objects.filter(name='Demo Project', scm_type='git').first()
scm_type='git', if not p:
scm_url='https://github.com/ansible/ansible-tower-samples', p = Project(
scm_update_on_launch=True, name='Demo Project',
scm_update_cache_timeout=0, scm_type='git',
) scm_url='https://github.com/ansible/ansible-tower-samples',
scm_update_on_launch=True,
scm_update_cache_timeout=0,
)
p.organization = o p.organization = o
p.save(skip_update=True) p.save(skip_update=True)