Skip to content

Commit ed80816

Browse files
authored
Fix schema alias handling in ConnectionResult (apache#46957)
1 parent 06db8ce commit ed80816

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

airflow/dag_processing/processor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def _handle_request(self, msg: ToManager, log: FilteringBoundLogger) -> None: #
277277
conn = self.client.connections.get(msg.conn_id)
278278
if isinstance(conn, ConnectionResponse):
279279
conn_result = ConnectionResult.from_conn_response(conn)
280-
resp = conn_result.model_dump_json(exclude_unset=True).encode()
280+
resp = conn_result.model_dump_json(exclude_unset=True, by_alias=True).encode()
281281
else:
282282
resp = conn.model_dump_json().encode()
283283
elif isinstance(msg, GetVariable):

task_sdk/src/airflow/sdk/execution_time/comms.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ def from_conn_response(cls, connection_response: ConnectionResponse) -> Connecti
139139
# Exclude defaults to avoid sending unnecessary data
140140
# Pass the type as ConnectionResult explicitly so we can then call model_dump_json with exclude_unset=True
141141
# to avoid sending unset fields (which are defaults in our case).
142-
return cls(**connection_response.model_dump(exclude_defaults=True), type="ConnectionResult")
142+
return cls(
143+
**connection_response.model_dump(exclude_defaults=True, by_alias=True), type="ConnectionResult"
144+
)
143145

144146

145147
class VariableResult(VariableResponse):

task_sdk/src/airflow/sdk/execution_time/supervisor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ def _handle_request(self, msg: ToSupervisor, log: FilteringBoundLogger):
787787
conn = self.client.connections.get(msg.conn_id)
788788
if isinstance(conn, ConnectionResponse):
789789
conn_result = ConnectionResult.from_conn_response(conn)
790-
resp = conn_result.model_dump_json(exclude_unset=True).encode()
790+
resp = conn_result.model_dump_json(exclude_unset=True, by_alias=True).encode()
791791
else:
792792
resp = conn.model_dump_json().encode()
793793
elif isinstance(msg, GetVariable):

task_sdk/tests/execution_time/test_supervisor.py

+9
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,15 @@ def watched_subprocess(self, mocker):
930930
ConnectionResult(conn_id="test_conn", conn_type="mysql"),
931931
id="get_connection",
932932
),
933+
pytest.param(
934+
GetConnection(conn_id="test_conn"),
935+
b'{"conn_id":"test_conn","conn_type":"mysql","schema":"mysql","type":"ConnectionResult"}\n',
936+
"connections.get",
937+
("test_conn",),
938+
{},
939+
ConnectionResult(conn_id="test_conn", conn_type="mysql", schema="mysql"), # type: ignore[call-arg]
940+
id="get_connection_with_alias",
941+
),
933942
pytest.param(
934943
GetVariable(key="test_key"),
935944
b'{"key":"test_key","value":"test_value","type":"VariableResult"}\n',

0 commit comments

Comments
 (0)