Open jplitza opened 12 months ago
I guess this is caused by unpartitioned_event_horizon()
:
https://github.com/ansible/awx/blob/fc0b58fd0472b732f36702431896d6d00d78dd19/awx/api/views/__init__.py#L130-L136
Maybe the error that Django throws here changed and the except ProgrammingError
doesn't catch that anymore?
Or rather, Django seems to internally repeat the query (see extended Postgres log). The first try might have resulted in a ProgrammingError
, but the second results in a different reaction from Postgres (because the transaction has to be rolled back first) and hence throws a different exception.
Actually, the catching of the ProgrammingError
works as intended. The only problem is that at some earlier point, a transaction was started, which isn't rolled back when the statement fails.
Inserting a transaction.rollback()
in the except block doesn't work either, because:
django.db.transaction.TransactionManagementError: This is forbidden when an 'atomic' block is active.
So as a workaround, I now first check if the table exists:
def unpartitioned_event_horizon(cls):
if f'_unpartitioned_{cls._meta.db_table}' not in connection.introspection.table_names():
return 0
with connection.cursor() as cursor:
cursor.execute(f'SELECT MAX(id) FROM _unpartitioned_{cls._meta.db_table}')
return cursor.fetchone()[0] or -1
I don't know whether this actually works when the unpartitioned table is present, but it works for me. :wink:
@AlanCoding is suggestion we modify the select statement to do the table introspection
e.g.
select case when EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'params')
then (select par_val from params where par_name='DBALIAS') else (select 'NOTABLE') end as DBAlias;
This is a high priority item, I will try to look at it today.
Please confirm the following
security@ansible.com
instead.)Bug Summary
Fetching any single job_event from the API throws a 500 Internal Server Error. To be precise:
AWX version
23.3.1
Select the relevant components
Installation method
kubernetes
Modifications
no
Ansible version
No response
Operating system
No response
Web browser
No response
Steps to reproduce
Fetch any single job_event from the API.
Expected results
Be provided with a response as it is contained e.g. in the
/api/v2/jobs/1234/job_events/
endpoint (which actually contains a link to this very API URL for every single job event).Actual results
Additional information
Log from the awx-web container:
The Postgres log contains the real error: