Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntegrityError: (psycopg2.IntegrityError) update or delete on table "query_results" violates foreign key constrai... #363

Closed
jezdez opened this issue Apr 9, 2018 · 1 comment
Assignees

Comments

@jezdez
Copy link

jezdez commented Apr 9, 2018

Seems like the process to cleanup results is broken due to the result sets:

https://sentry.prod.mozaws.net/operations/data-stmo-prod/issues/3460864/

IntegrityError: (psycopg2.IntegrityError) update or delete on table "query_results" violates foreign key constraint "queries_latest_query_data_id_fkey" on table "queries"
DETAIL:  Key (id)=(3570734) is still referenced from table "queries".
 [SQL: 'DELETE FROM query_results WHERE query_results.id IN (SELECT query_results.id \nFROM query_results \nWHERE query_results.retrieved_at < %(retrieved_at_1)s AND NOT (EXISTS (SELECT 1 \nFROM query_resultsets \nWHERE query_resultsets.result_id = query_results.id)) \n LIMIT %(param_1)s)'] [parameters: {'retrieved_at_1': datetime.datetime(2018, 4, 2, 18, 35, 6, 406886), 'param_1': 100}]
(11 additional frame(s) were not displayed)
...
  File "sqlalchemy/engine/base.py", line 1189, in _execute_context
    context)
  File "sqlalchemy/engine/base.py", line 1393, in _handle_dbapi_exception
    exc_info
  File "sqlalchemy/util/compat.py", line 202, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "sqlalchemy/engine/base.py", line 1182, in _execute_context
    context)
  File "sqlalchemy/engine/default.py", line 469, in do_execute
    cursor.execute(statement, parameters)

IntegrityError: (psycopg2.IntegrityError) update or delete on table "query_results" violates foreign key constraint "queries_latest_query_data_id_fkey" on table "queries"
DETAIL:  Key (id)=(3570734) is still referenced from table "queries".
 [SQL: 'DELETE FROM query_results WHERE query_results.id IN (SELECT query_results.id \nFROM query_results \nWHERE query_results.retrieved_at < %(retrieved_at_1)s AND NOT (EXISTS (SELECT 1 \nFROM query_resultsets \nWHERE query_resultsets.result_id = query_results.id)) \n LIMIT %(param_1)s)'] [parameters: {'retrieved_at_1': datetime.datetime(2018, 4, 2, 18, 35, 6, 406886), 'param_1': 100}]
@washort
Copy link

washort commented Apr 9, 2018

This was an oversight due to deficient tests when changing around the delete code to accommodate storing multiple results per query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants