hussein-awala commented on issue #32048:
URL: https://github.com/apache/airflow/issues/32048#issuecomment-1601764479
Yes I see that this can affect some users.
> But I think we cannot (Without bumping Airflow 2 to Airflow 3) change the
way "airflow db init" behaves by default (at most it can raise a warning)
I think we can deprecate just the part which create the connections (not all
the init method), ask the users to set it to False manually, and create a new
alternative command to create the default connections. Something similar to
```diff
diff --git a/airflow/cli/cli_config.py b/airflow/cli/cli_config.py
index 0c69571fea..7811662841 100644
--- a/airflow/cli/cli_config.py
+++ b/airflow/cli/cli_config.py
@@ -1566,6 +1566,12 @@ DB_COMMANDS = (
func=lazy_load_command("airflow.cli.commands.db_command.initdb"),
args=(ARG_VERBOSE,),
),
+ ActionCommand(
+ name="create-default-connections",
+ help="Create default connections",
+
func=lazy_load_command("airflow.cli.commands.db_command.create_default_connections"),
+ args=(ARG_VERBOSE,),
+ ),
ActionCommand(
name="check-migrations",
help="Check if migration have finished",
diff --git a/airflow/cli/commands/db_command.py
b/airflow/cli/commands/db_command.py
index 64d54cc22e..db044c0ee7 100644
--- a/airflow/cli/commands/db_command.py
+++ b/airflow/cli/commands/db_command.py
@@ -246,3 +246,8 @@ def drop_archived(args):
table_names=args.tables,
needs_confirm=not args.yes,
)
+
+
+def create_default_connections(args):
+ """Create default connections"""
+ db.create_default_connections()
diff --git a/airflow/utils/db.py b/airflow/utils/db.py
index a76f0d4f67..17236c6932 100644
--- a/airflow/utils/db.py
+++ b/airflow/utils/db.py
@@ -732,6 +732,13 @@ def initdb(session: Session = NEW_SESSION,
load_connections: bool = True):
_create_db_from_orm(session=session)
# Load default connections
if conf.getboolean("database", "LOAD_DEFAULT_CONNECTIONS") and
load_connections:
+ warnings.warn(
+ "Creating default connections via the command `airflow db init`
is deprecated.\n"
+ "Please use `airflow db create-default-connections` instead and
"
+ "set database.load_default_connections to False.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
create_default_connections(session=session)
# Add default pool & sync log_template
add_default_pool_if_not_exists(session=session)
```
Then we can remove it after 2 or 3 minor versions if the Airflow core
release policy allows us to do like that, otherwise in Airflow 3 as you said.
But if the command `airflow db upgrade` can replace the command `airflow db
init` (except the part of default connections), we can deprecate the whole
command `db init` and warn the user to use the two commands `db upgrade` + `db
create-default-connections` instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]