Skip to content

PR #18772 breaks sql_alchemy_conn_cmd config #20092

Closed

Description

@xyu

Apache Airflow version

2.2.1

What happened

#18772 added two options to tmp_configuration_copy() and defaults tasks run as the same user to generate the temp configuration file for the task runner with the options include_env=False and include_cmds=False. This is a change from the previous defaults which materialized the values of *_cmd configs into the JSON dump.

This presents a problem because when using sql_alchemy_conn_cmd to set the database connection and running as the same user the temporary config JSON dump now includes both sql_alchemy_conn, set to the Airflow distribution default as well as the user set sql_alchemy_conn_cmd. And because bare settings take precedence over _cmd versions while the Airflow worker can connect to the configured DB the task runner itself will instead use a non-existent SQLite DB causing all tasks to fail.

TLDR; The temp JSON config dump used to look something like:

{
  "core": {
    "sql_alchemy_conn": "mysql://...",
    ...
  }
}

Now it looks something like:


{
  "core": {
    "sql_alchemy_conn": "sqlite:////var/opt/airflow/airflow.db",
    "sql_alchemy_conn_cmd": "/etc/airflow/get-config 'core/sql_alchemy_conn'"
    ...
  }
}

But because sql_alchemy_conn is set sql_alchemy_conn_cmd never gets called and tasks are unable to access the Airflow DB.

What you expected to happen

I'm not quite sure what is the preferred method to fix this issue. I guess there are a couple options:

  • Remove the bare sensitive_config_values if either _cmd or _secret versions exist
  • Ignore the Airflow default value in addition to empty values for bare sensitive_config_values during parsing
  • Go back to materializing the sensitive configs

How to reproduce

With either Airflow 2.2.1 or 2.2.2 configure the DB with sql_alchemy_conn_cmd and remove the sql_alchemy_conn config from your config file. Then run the Airflow worker and task runner as the same user. Try running any task and see that the task tries to access the default SQLite store instead of the configured one.

Operating System

Debian Bullseye

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

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

Activity

  1. xyu commented on Dec 7, 2021

    @xyu
    ContributorAuthor

    I guess @karry-li-lego opened #19833 for this same issue, I'm not sure why they closed it because this problem is still valid on the main trunk branch.

  2. eladkal commented on Dec 19, 2021

    @eladkal
    Contributor
  3. ashb commented on Dec 19, 2021

    @ashb
    Member

    And because bare settings take precedence over _cmd versions

    This isn't meant to be the case

  4. potiuk commented on Dec 19, 2021

    @potiuk
    Member

    This isn't meant to be the case

    Actually it does, and it's even documented:

    https://airflow.apache.org/docs/apache-airflow/stable/howto/set-config.html

    The universal order of precedence for all configuration options is as follows:

    • set as an environment variable (AIRFLOW__CORE__SQL_ALCHEMY_CONN)
    • set as a command environment variable (AIRFLOW__CORE__SQL_ALCHEMY_CONN_CMD)
    • set as a secret environment variable (AIRFLOW__CORE__SQL_ALCHEMY_CONN_SECRET)
    • set in airflow.cfg
    • command in airflow.cfg
    • secret key in airflow.cfg
    • Airflow’s built in defaults

    This is also main reason why we are implementing this one: #18974

  5. sydykov commented on Jan 20, 2022

    @sydykov

    Hi! Is someone working on this?

  6. xyu commented on Jan 28, 2022

    @xyu
    ContributorAuthor

    @ashb do you have a preferred method to resolve this of the three I mentioned above or perhaps some other idea?

  7. added a commit that references this issue on Feb 12, 2022
    00f7e57
  8. 2ps commented on Feb 18, 2022

    @2ps

    Hello, we submitted a PR that works for us on this issue.

  9. added a commit that references this issue on Mar 15, 2022
    e07bc63
  10. added 10 commits that reference this issue on Mar 16, 2022
    b794415
    eae3f0d
    72501a6
    fed7cd5
    66c31a6
    30dc3f4
    f758593
    94f698f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions