Skip to content

Commit

Permalink
Guard around race condition (#15452)
Browse files Browse the repository at this point in the history
I had the luck of running into this race condition that broke my deployment. No instance was ever able to register because on running "awx-manage" in some check of a setting, it would end up failing here with

```
  File "/var/lib/awx/venv/awx/lib64/python3.11/site-packages/awx/conf/license.py", line 10, in _get_validated_license_data
    return get_licenser().validate()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/lib/awx/venv/awx/lib64/python3.11/site-packages/awx/main/utils/licensing.py", line 453, in validate
    automated_since = int(Instance.objects.order_by('id').first().created.timestamp())
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'created'
```
  • Loading branch information
kdelee authored Aug 20, 2024
1 parent 39d1922 commit c5c617b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion awx/main/utils/licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,12 @@ def validate(self):
if first_host:
automated_since = int(first_host.first_automation.timestamp())
else:
automated_since = int(Instance.objects.order_by('id').first().created.timestamp())
try:
automated_since = int(Instance.objects.order_by('id').first().created.timestamp())
except AttributeError:
# In the odd scenario that create_preload_data was not run, there are no hosts
# Then we CAN end up here before any instance has registered
automated_since = int(time.time())
instance_count = int(attrs.get('instance_count', 0))
attrs['current_instances'] = current_instances
attrs['automated_instances'] = automated_instances
Expand Down

0 comments on commit c5c617b

Please sign in to comment.