AlejandroMorgante commented on code in PR #68799: URL: https://github.com/apache/airflow/pull/68799#discussion_r3509617698
########## providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/ai_agents.py: ########## @@ -0,0 +1,457 @@ +# +# 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. +from __future__ import annotations + +import asyncio +import json +from functools import cached_property +from typing import TYPE_CHECKING, Any, cast +from urllib.parse import quote + +from azure.core.exceptions import ResourceNotFoundError +from azure.identity import ClientSecretCredential +from requests import Session +from requests.exceptions import HTTPError + +from airflow.providers.common.compat.sdk import BaseHook +from airflow.providers.microsoft.azure.hooks.base_azure import _AZURE_CLOUD_ENVIRONMENTS +from airflow.providers.microsoft.azure.utils import ( + add_managed_identity_connection_widgets, + get_field, + get_sync_default_azure_credential, +) + +if TYPE_CHECKING: + from azure.core.credentials import TokenCredential + from requests import Response + + from airflow.sdk import Connection + + +HOSTED_AGENT_FEATURE_HEADER = "HostedAgents=V1Preview" +TOKEN_SCOPE = "https://ai.azure.com/.default" +VERSION_INTERMEDIATE_STATUSES = {"creating", "deleting"} +VERSION_SUCCESS_STATUSES = {"active"} +VERSION_FAILURE_STATUSES = {"failed"} + + +def serialize_resource(resource: Any) -> Any: + """Serialize an SDK or HTTP response object into XCom-safe primitives.""" + if resource is None or isinstance(resource, str | int | float | bool): + return resource + if isinstance(resource, list | tuple): + return [serialize_resource(item) for item in resource] + if isinstance(resource, dict): + return {key: serialize_resource(value) for key, value in resource.items()} + if hasattr(resource, "as_dict"): + return serialize_resource(resource.as_dict()) + if hasattr(resource, "model_dump"): + return serialize_resource(resource.model_dump()) + if hasattr(resource, "__dict__"): Review Comment: Good catch. I removed the permissive `__dict__` fallback so we only serialize primitives, mappings/sequences, and resources with explicit serializers (`as_dict()` / `model_dump()`). I also added tests covering both an explicit model serializer and an arbitrary object that should be left untouched -- 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]
