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

BUG: scrub valid user tables if tablename used previously #247

Open
kimakan opened this issue Sep 18, 2024 · 0 comments
Open

BUG: scrub valid user tables if tablename used previously #247

kimakan opened this issue Sep 18, 2024 · 0 comments
Labels

Comments

@kimakan
Copy link
Contributor

kimakan commented Sep 18, 2024

The main purpose of the management command scrub_user_tables is to check whether there are any user in the database where the corresponding query job is not in the phase COMPLETED or EXECUTING. The found tables can be deleted if the flag --delete is used.

The selection of tables happens here

for table in tables:
job = QueryJob.objects.filter(
schema_name=schema_name,
table_name=table['name']
).first()
if job and job.phase not in [QueryJob.PHASE_EXECUTING, QueryJob.PHASE_COMPLETED]:
stale_tables.append((schema_name, table['name'], job.phase if job else None))

The issue occurs if the table name is used several times after archiving previous tables. In this case, there are several jobs using the same table name where only one of the jobs has the valid phase. It's not guaranteed that during the filtering we get the job with the correct phase.

                job = QueryJob.objects.filter(
                    schema_name=schema_name,
                    table_name=table['name']
                ).first()

Proposed solution
I think that ordering of the result by creation date before executing first() might solve the issue. Only the most current queryjob using the table name must be valid.

@kimakan kimakan added bug app:query concern the query-app priority:high labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant