o-nikolas commented on code in PR #65269: URL: https://github.com/apache/airflow/pull/65269#discussion_r3127365724
########## airflow-core/newsfragments/65269.significant.rst: ########## @@ -0,0 +1 @@ +Synchronous deadline callbacks (``SyncCallback``) can now access Connections, Variables, XCom, and Assets from the Airflow metadata database. Review Comment: Asset portion was reverted but still mentioned here ########## task-sdk/src/airflow/sdk/execution_time/request_handlers.py: ########## @@ -0,0 +1,95 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" +Shared request handlers for supervised subprocess comms channels. + +These functions implement the supervisor-side logic for message types that are +used by more than one subprocess type (tasks, callbacks, triggerer). Each +handler accepts a ``Client`` and a request message and returns +``(response_model | None, dump_opts)`` so the caller can forward the result +via ``send_msg``. +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from airflow.sdk.api.datamodels._generated import ( + AssetResponse, + ConnectionResponse, + VariableResponse, +) +from airflow.sdk.execution_time.comms import ( + AssetResult, + ConnectionResult, + GetAssetByName, + GetAssetByUri, + GetConnection, + GetVariable, + MaskSecret, + VariableResult, +) +from airflow.sdk.log import mask_secret + +if TYPE_CHECKING: + from pydantic import BaseModel + + from airflow.sdk.api.client import Client + + +def handle_get_connection(client: Client, msg: GetConnection) -> tuple[BaseModel | None, dict[str, bool]]: + """Fetch a connection and mask its sensitive fields.""" + conn = client.connections.get(msg.conn_id) + if isinstance(conn, ConnectionResponse): + if conn.password: + mask_secret(conn.password) + if conn.extra: + mask_secret(conn.extra) + return ConnectionResult.from_conn_response(conn), {"exclude_unset": True, "by_alias": True} + return conn, {} + + +def handle_get_variable(client: Client, msg: GetVariable) -> tuple[BaseModel | None, dict[str, bool]]: + """Fetch a variable and mask its value.""" + var = client.variables.get(msg.key) + if isinstance(var, VariableResponse): + if var.value: + mask_secret(var.value, var.key) + return VariableResult.from_variable_response(var), {"exclude_unset": True} + return var, {} + + +def handle_get_asset_by_name(client: Client, msg: GetAssetByName) -> tuple[BaseModel | None, dict[str, bool]]: + """Fetch an asset by name.""" + asset_resp = client.assets.get(name=msg.name) + if isinstance(asset_resp, AssetResponse): + return AssetResult.from_asset_response(asset_resp), {"exclude_unset": True} + return asset_resp, {} + + +def handle_get_asset_by_uri(client: Client, msg: GetAssetByUri) -> tuple[BaseModel | None, dict[str, bool]]: + """Fetch an asset by URI.""" + asset_resp = client.assets.get(uri=msg.uri) + if isinstance(asset_resp, AssetResponse): + return AssetResult.from_asset_response(asset_resp), {"exclude_unset": True} + return asset_resp, {} Review Comment: Are these still needed now that Assets were dropped? I don't see them used anywhere. -- 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]
