Skip to content
18 changes: 15 additions & 3 deletions airflow-core/src/airflow/cli/commands/connection_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,26 +411,38 @@ def _import_helper(file_path: str, overwrite: bool) -> None:
:param overwrite: Whether to skip or overwrite on collision.
"""
connections_dict = load_connections_dict(file_path)
suc_count = fail_count = 0
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suc_count is an unclear abbreviation. Rename to something explicit like success_count (and keep fail_count as failure_count for symmetry) to improve readability.

Copilot uses AI. Check for mistakes.
with create_session() as session:
for conn_id, conn in connections_dict.items():
try:
helpers.validate_key(conn_id, max_length=200)
except Exception as e:
print(f"Could not import connection. {e}")
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error messages are inconsistent (one omits conn_id, and the other uses repr formatting via {e!r} which can be noisy). For a more consistent CLI UX, include conn_id in both cases and standardize formatting (e.g., include the exception type + message).

Copilot uses AI. Check for mistakes.
fail_count += 1
continue

existing_conn_id = session.scalar(select(Connection.id).where(Connection.conn_id == conn_id))
if existing_conn_id is not None:
if not overwrite:
print(f"Could not import connection {conn_id}: connection already exists.")
fail_count += 1
continue

# The conn_ids match, but the PK of the new entry must also be the same as the old
conn.id = existing_conn_id

session.merge(conn)
session.commit()
print(f"Imported connection {conn_id}")
try:
session.merge(conn)
session.commit()
except Exception as e:
print(f"Connection import failed for {conn_id}: {e!r}")
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error messages are inconsistent (one omits conn_id, and the other uses repr formatting via {e!r} which can be noisy). For a more consistent CLI UX, include conn_id in both cases and standardize formatting (e.g., include the exception type + message).

Copilot uses AI. Check for mistakes.
session.rollback()
fail_count += 1
else:
suc_count += 1
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes the per-connection success output (Imported connection {conn_id}), so large imports may appear to 'hang' with no progress feedback until the end. Consider retaining a per-item success message (or gating it behind a verbosity flag) while keeping the end summary.

Suggested change
suc_count += 1
suc_count += 1
print(f"Imported connection {conn_id}")

Copilot uses AI. Check for mistakes.
print(f"{suc_count} of {len(connections_dict)} connections successfully imported.")
if fail_count:
print(f"{fail_count} connection(s) failed to be imported.")


@suppress_logs_and_warning
Expand Down
Loading