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

airflow db clean - table missing exception not captured #23698

Closed
2 tasks done
jianyuan opened this issue May 13, 2022 · 1 comment · Fixed by #23699
Closed
2 tasks done

airflow db clean - table missing exception not captured #23698

jianyuan opened this issue May 13, 2022 · 1 comment · Fixed by #23699
Labels
affected_version:2.3 Issues Reported for 2.3 area:CLI area:core kind:bug This is a clearly a bug
Milestone

Comments

@jianyuan
Copy link
Contributor

Apache Airflow version

2.3.0 (latest released)

What happened

I am running on the Kubernetes Executor, so Celery-related tables were never created. I am using PostgreSQL as the database.

When I ran airflow db clean, it gave me the following exception:

Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1705, in _execute_context
    self.dialect.do_execute(
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 716, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.UndefinedTable: relation "celery_taskmeta" does not exist
LINE 3: FROM celery_taskmeta 
             ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/airflow/.local/bin/airflow", line 8, in <module>
    sys.exit(main())
  File "/home/airflow/.local/lib/python3.9/site-packages/airflow/__main__.py", line 38, in main
    args.func(args)
  File "/home/airflow/.local/lib/python3.9/site-packages/airflow/cli/cli_parser.py", line 51, in command
    return func(*args, **kwargs)
  File "/home/airflow/.local/lib/python3.9/site-packages/airflow/utils/cli.py", line 99, in wrapper
    return f(*args, **kwargs)
  File "/home/airflow/.local/lib/python3.9/site-packages/airflow/cli/commands/db_command.py", line 195, in cleanup_tables
    run_cleanup(
  File "/home/airflow/.local/lib/python3.9/site-packages/airflow/utils/session.py", line 71, in wrapper
    return func(*args, session=session, **kwargs)
  File "/home/airflow/.local/lib/python3.9/site-packages/airflow/utils/db_cleanup.py", line 311, in run_cleanup
    _cleanup_table(
  File "/home/airflow/.local/lib/python3.9/site-packages/airflow/utils/db_cleanup.py", line 228, in _cleanup_table
    _print_entities(query=query, print_rows=False)
  File "/home/airflow/.local/lib/python3.9/site-packages/airflow/utils/db_cleanup.py", line 137, in _print_entities
    num_entities = query.count()
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3062, in count
    return self._from_self(col).enable_eagerloads(False).scalar()
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2803, in scalar
    ret = self.one()
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2780, in one
    return self._iter().one()
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 2818, in _iter
    result = self.session.execute(
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1670, in execute
    result = conn._execute_20(statement, params or {}, execution_options)
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1520, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/sql/elements.py", line 313, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1389, in _execute_clauseelement
    ret = self._execute_context(
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1748, in _execute_context
    self._handle_dbapi_exception(
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1929, in _handle_dbapi_exception
    util.raise_(
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1705, in _execute_context
    self.dialect.do_execute(
  File "/home/airflow/.local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 716, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "celery_taskmeta" does not exist
LINE 3: FROM celery_taskmeta 
             ^

[SQL: SELECT count(*) AS count_1 
FROM (SELECT celery_taskmeta.id AS celery_taskmeta_id, celery_taskmeta.task_id AS celery_taskmeta_task_id, celery_taskmeta.status AS celery_taskmeta_status, celery_taskmeta.result AS celery_taskmeta_result, celery_taskmeta.date_done AS celery_taskmeta_date_done, celery_taskmeta.traceback AS celery_taskmeta_traceback 
FROM celery_taskmeta 
WHERE celery_taskmeta.date_done < %(date_done_1)s) AS anon_1]
[parameters: {'date_done_1': DateTime(2022, 1, 1, 0, 0, 0, tzinfo=Timezone('UTC'))}]
(Background on this error at: http://sqlalche.me/e/14/f405)

What you think should happen instead

No response

How to reproduce

  1. Use an executor that do not require Celery
  2. Use PostgreSQL as the database
  3. Run airflow db clean

Operating System

Debian GNU/Linux 11 (bullseye)

Versions of Apache Airflow Providers

No response

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@jianyuan jianyuan added area:core kind:bug This is a clearly a bug labels May 13, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented May 13, 2022

Thanks for opening your first issue here! Be sure to follow the issue template!

@jianyuan jianyuan changed the title airflow db clean - airflow db clean - table missing exception not captured May 13, 2022
@eladkal eladkal added this to the Airflow 2.3.1 milestone May 15, 2022
@eladkal eladkal added the affected_version:2.3 Issues Reported for 2.3 label May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected_version:2.3 Issues Reported for 2.3 area:CLI area:core kind:bug This is a clearly a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants