You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Victor Villas Bôas Chaves (JIRA)" <ji...@apache.org> on 2019/08/13 11:24:00 UTC

[jira] [Created] (AIRFLOW-5194) Remove action_logging from cli commands that could happen before db is initialized

Victor Villas Bôas Chaves created AIRFLOW-5194:
--------------------------------------------------

             Summary: Remove action_logging from cli commands that could happen before db is initialized
                 Key: AIRFLOW-5194
                 URL: https://issues.apache.org/jira/browse/AIRFLOW-5194
             Project: Apache Airflow
          Issue Type: Improvement
          Components: cli
    Affects Versions: 1.10.4
            Reporter: Victor Villas Bôas Chaves


https://issues.apache.org/jira/browse/AIRFLOW-2253 introduced `@cli_utils.action_logging` to CLI commands, but a few of those commands are reasonably expected to run before the database has been initialized. On doing so, an `relation "log" does not exist` error pops out (see below for a complete output).

 

https://issues.apache.org/jira/browse/AIRFLOW-2436 was created and solved that problem in the `initdb` command itself, but this still affects two commands that are often used before tables exist: `version` and `upgradedb` itself.

`upgradedb` is frequently used as a kind of `initdb` that won't load default connections, so quite a few people use it to initialize the db as well.

So I propose that we remove `@cli_utils.action_logging` from the commands:
 * version
 * upgradedb

 
{code:java}
[root@ip-10-0-11-97 ~]# /usr/local/bin/airflow version
/usr/local/lib/python3.7/site-packages/airflow/configuration.py:614: DeprecationWarning: You have two airflow.cfg files: /root/airflow/airflow.cfg and /airflow/airflow.cfg. Airflow used to look at ~/airflow/airflow.cfg, even when AIRFLOW_HOME was set to a different value. Airflow will now only read /airflow/airflow.cfg, and you should remove the other file
  category=DeprecationWarning,
[2019-08-13 11:13:39,985] {settings.py:213} INFO - settings.configure_orm(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=3547
/usr/local/lib64/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
[2019-08-13 11:13:40,188] {__init__.py:51} INFO - Using executor CeleryExecutor
[2019-08-13 11:13:40,524] {cli_action_loggers.py:70} ERROR - Failed on pre-execution callback using <function default_action_log at 0x7fc6e1afe200>
Traceback (most recent call last):
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1244, in _execute_context
    cursor, statement, parameters, context
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/default.py", line 552, in do_execute
    cursor.execute(statement, parameters)
psycopg2.ProgrammingError: relation "log" does not exist
LINE 1: INSERT INTO log (dttm, dag_id, task_id, event, execution_dat...
                    ^


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

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/airflow/utils/cli_action_loggers.py", line 68, in on_pre_execution
    cb(**kwargs)
  File "/usr/local/lib/python3.7/site-packages/airflow/utils/cli_action_loggers.py", line 99, in default_action_log
    session.add(log)
  File "/usr/lib64/python3.7/contextlib.py", line 119, in __exit__
    next(self.gen)
  File "/usr/local/lib/python3.7/site-packages/airflow/utils/db.py", line 45, in create_session
    session.commit()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/session.py", line 1027, in commit
    self.transaction.commit()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/session.py", line 494, in commit
    self._prepare_impl()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/session.py", line 473, in _prepare_impl
    self.session.flush()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/session.py", line 2459, in flush
    self._flush(objects)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/session.py", line 2597, in _flush
    transaction.rollback(_capture_exception=True)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/util/compat.py", line 153, in reraise
    raise value
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/session.py", line 2557, in _flush
    flush_context.execute()
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/unitofwork.py", line 422, in execute
    rec.execute(self)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/unitofwork.py", line 589, in execute
    uow,
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/persistence.py", line 245, in save_obj
    insert,
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/orm/persistence.py", line 1138, in _emit_insert_statements
    statement, params
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 988, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/sql/elements.py", line 287, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1107, in _execute_clauseelement
    distilled_params,
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context
    e, statement, parameters, cursor, context
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1466, in _handle_dbapi_exception
    util.raise_from_cause(sqlalchemy_exception, exc_info)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/util/compat.py", line 152, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/base.py", line 1244, in _execute_context
    cursor, statement, parameters, context
  File "/usr/local/lib64/python3.7/site-packages/sqlalchemy/engine/default.py", line 552, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) relation "log" does not exist
LINE 1: INSERT INTO log (dttm, dag_id, task_id, event, execution_dat...
                    ^

[SQL: INSERT INTO log (dttm, dag_id, task_id, event, execution_date, owner, extra) VALUES (%(dttm)s, %(dag_id)s, %(task_id)s, %(event)s, %(execution_date)s, %(owner)s, %(extra)s) RETURNING log.id]
[parameters: {'dttm': datetime.datetime(2019, 8, 13, 11, 13, 40, 486015, tzinfo=<Timezone [UTC]>), 'dag_id': None, 'task_id': None, 'event': 'cli_version', 'execution_date': None, 'owner': 'root', 'extra': '{"host_name": "ip-10-0-11-97.ec2.internal", "full_command": "[\'/usr/local/bin/airflow\', \'version\']"}'}]
(Background on this error at: http://sqlalche.me/e/f405)
  ____________       _____________
 ____    |__( )_________  __/__  /________      __
____  /| |_  /__  ___/_  /_ __  /_  __ \_ | /| / /
___  ___ |  / _  /   _  __/ _  / / /_/ /_ |/ |/ /
 _/_/  |_/_/  /_/    /_/    /_/  \____/____/|__/  v1.10.4
{code}



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)