dabla opened a new issue, #72316:
URL: https://github.com/apache/airflow/issues/72316

   ### Under which category would you file this issue?
   
   Providers
   
   ### Apache Airflow version
   
   Not version-specific — reproducible on any version shipping 
`apache-airflow-providers-common-ai` with `PydanticAIAzureHook`, 
`PydanticAIBedrockHook`, or `PydanticAIVertexHook`.
   
   ### What happened and how to reproduce it?
   
   `Connection.get_hook()` raises `AirflowException: Unknown hook type 
"pydanticai_azure"` (or
   `pydanticai_bedrock` / `pydanticai_vertex`) whenever the connection is 
stored as a URI in a
   secrets backend such as HashiCorp Vault or AWS Secrets Manager.
   
   **Stack trace:**
   
   ```
   AirflowException: Unknown hook type "pydanticai_azure"
     File ".../airflow/sdk/execution_time/task_runner.py", line 1579 in 
_run_task_and_map_outcome
     File ".../airflow/sdk/definitions/connection.py", line 223 in get_hook
   ```
   
   **How to reproduce:**
   
   1. Store a connection whose type is `pydanticai-azure` as a URI in a secrets 
backend
      (e.g. `pydanticai-azure://<host>?...` in HashiCorp Vault).
   2. Reference that connection from a Dag using `@task.agent` / 
`AgentOperator`.
   3. The task fails with `Unknown hook type "pydanticai_azure"`.
   
   The bug does **not** reproduce when the connection is stored in the metadata 
DB directly, because
   in that case `conn_type` is stored as a plain field and never passes through 
URI normalization.
   
   **Root cause:**
   
   `Connection.get_uri()` serializes `conn_type` with hyphens to produce a 
valid URI scheme:
   
   ```python
   uri = f"{self.conn_type.lower().replace('_', '-')}://"
   ```
   
   `Connection._normalize_conn_type()` is the intended reverse — it converts 
hyphens back to
   underscores when a URI is parsed:
   
   ```python
   elif "-" in conn_type:
       conn_type = conn_type.replace("-", "_")
   ```
   
   This round-trip works correctly for every other multi-word hook in the 
codebase because they all
   declare their `conn_type` with underscores:
   
   | Hook | `conn_type` | URI scheme |
   |---|---|---|
   | Azure Data Factory | `azure_data_factory` | `azure-data-factory://` |
   | Google Cloud Platform | `google_cloud_platform` | 
`google-cloud-platform://` |
   | Hive CLI | `hive_cli` | `hive-cli://` |
   | Spark Connect | `spark_connect` | `spark-connect://` |
   
   The three pydantic-ai hooks are the **only outliers** in the entire provider 
tree — they declare
   their `conn_type` with hyphens in both `provider.yaml` and the hook class:
   
   ```python
   # providers/common/ai/hooks/pydantic_ai.py
   class PydanticAIAzureHook(...):
       conn_type = "pydanticai-azure"   # ← hyphen; all other multi-word hooks 
use underscore
   
   class PydanticAIBedrockHook(...):
       conn_type = "pydanticai-bedrock"
   
   class PydanticAIVertexHook(...):
       conn_type = "pydanticai-vertex"
   ```
   
   ```yaml
   # providers/common/ai/provider.yaml
   connection-type: pydanticai-azure
   connection-type: pydanticai-bedrock
   connection-type: pydanticai-vertex
   ```
   
   So the broken round-trip is:
   
   ```
   URI from secrets backend : "pydanticai-azure://..."
     → _normalize_conn_type() → "pydanticai_azure"   (underscore form)
     → hooks.get("pydanticai_azure") → None           (hook is registered under 
"pydanticai-azure")
     → AirflowException: Unknown hook type "pydanticai_azure"
   
   ### What you think should happen instead?
   
   The three hook `conn_type` attributes and the corresponding `provider.yaml` 
`connection-type`
   entries should be renamed to use underscores, consistent with every other 
multi-word provider:
   
   | Current | Proposed |
   |---|---|
   | `pydanticai-azure` | `pydanticai_azure` |
   | `pydanticai-bedrock` | `pydanticai_bedrock` |
   | `pydanticai-vertex` | `pydanticai_vertex` |
   
   `default_conn_name` values already use underscores 
(`pydanticai_azure_default`) so those are
   unaffected.
   
   Since these providers are relatively new, migration impact should be 
limited. A
   `_normalize_conn_type` alias (like the existing `postgresql` → `postgres` 
entry) could be added
   as a compatibility shim for users who already have connections stored with 
the hyphenated type.
   
   ### Operating System
   
   Redhat 44
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Apache Airflow Provider(s)
   
   common-ai
   
   ### Versions of Apache Airflow Providers
   
   All versions shipping `PydanticAIAzureHook`, `PydanticAIBedrockHook`, or 
`PydanticAIVertexHook`.
   
   ### Official Helm Chart version
   
   1.22.0 (latest released)
   
   ### Kubernetes Version
   
   _No response_
   
   ### Helm Chart configuration
   
   _No response_
   
   ### Docker Image customizations
   
   _No response_
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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]

Reply via email to