Skip to content

Commit 40497e1

Browse files
Leondon9ruvnet
andcommitted
Add regression test for connection import without extra field
Covers the case where `extra` is omitted from the JSON input, which caused a Pydantic ValidationError before the fix. Co-Authored-By: claude-flow <ruv@ruv.net>
1 parent b9c6199 commit 40497e1

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

airflow-ctl/tests/airflow_ctl/ctl/commands/test_connections_command.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
from __future__ import annotations
1818

1919
import json
20+
from unittest.mock import patch
2021

2122
import pytest
2223

2324
from airflowctl.api.client import ClientKind
2425
from airflowctl.api.datamodels.generated import (
2526
BulkActionResponse,
2627
BulkResponse,
28+
ConnectionBody,
2729
ConnectionCollectionResponse,
2830
ConnectionResponse,
2931
)
@@ -125,3 +127,52 @@ def test_import_error(self, api_client_maker, tmp_path, monkeypatch):
125127
self.parser.parse_args(["connections", "import", expected_json_path.as_posix()]),
126128
api_client=api_client,
127129
)
130+
131+
def test_import_without_extra_field(self, api_client_maker, tmp_path, monkeypatch):
132+
"""Import succeeds when JSON omits the ``extra`` field (#62653).
133+
134+
Before the fix, ``v.get("extra", {})`` returned ``{}`` (a dict) when
135+
the key was absent, but ``ConnectionBody.extra`` expects ``str | None``,
136+
causing a Pydantic ``ValidationError``.
137+
"""
138+
api_client = api_client_maker(
139+
path="/api/v2/connections",
140+
response_json=self.bulk_response_success.model_dump(),
141+
expected_http_status_code=200,
142+
kind=ClientKind.CLI,
143+
)
144+
145+
monkeypatch.chdir(tmp_path)
146+
json_path = tmp_path / self.export_file_name
147+
# Intentionally omit "extra" (and several other optional keys) to
148+
# mirror a minimal real-world connection JSON export.
149+
connection_file = {
150+
self.connection_id: {
151+
"conn_type": "test_type",
152+
"host": "test_host",
153+
}
154+
}
155+
156+
json_path.write_text(json.dumps(connection_file))
157+
158+
with patch(
159+
"airflowctl.ctl.commands.connection_command.ConnectionBody",
160+
wraps=ConnectionBody,
161+
) as mock_body:
162+
connection_command.import_(
163+
self.parser.parse_args(["connections", "import", json_path.as_posix()]),
164+
api_client=api_client,
165+
)
166+
167+
# Verify that ``extra`` was passed as None (not {} which would fail
168+
# Pydantic validation) and all other absent keys default correctly.
169+
mock_body.assert_called_once_with(
170+
connection_id=self.connection_id,
171+
conn_type="test_type",
172+
host="test_host",
173+
login=None,
174+
password=None,
175+
port=None,
176+
extra=None,
177+
description="",
178+
)

0 commit comments

Comments
 (0)