This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 55ff4cf935 fix(providers/azure): remove json.dumps when querying 
AzureCosmosDBHook (#33653)
55ff4cf935 is described below

commit 55ff4cf9351585dcd51cf324f4c2b538176b8aae
Author: Wei Lee <[email protected]>
AuthorDate: Sat Aug 26 01:37:13 2023 +0800

    fix(providers/azure): remove json.dumps when querying AzureCosmosDBHook 
(#33653)
    
    * fix(providers/azure): remove json.dumps when querying cosmos
    
    json.dumps leads to "azure.cosmos.exceptions.CosmosHttpResponseError: 
(BadRequest) Message: {"Errors":["Invalid query. Specified parameterized query 
JSON is malformed."]}"
    
    * docs(providers/microsoft): add comment for the type ignoring
---
 airflow/providers/microsoft/azure/hooks/cosmos.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/airflow/providers/microsoft/azure/hooks/cosmos.py 
b/airflow/providers/microsoft/azure/hooks/cosmos.py
index 3a73eeada7..4b42217e68 100644
--- a/airflow/providers/microsoft/azure/hooks/cosmos.py
+++ b/airflow/providers/microsoft/azure/hooks/cosmos.py
@@ -25,7 +25,6 @@ the default database and collection to use (see connection 
`azure_cosmos_default
 """
 from __future__ import annotations
 
-import json
 import uuid
 from typing import Any
 
@@ -145,12 +144,14 @@ class AzureCosmosDBHook(BaseHook):
         if collection_name is None:
             raise AirflowBadRequest("Collection name cannot be None.")
 
+        # The ignores below is due to typing bug in azure-cosmos 9.2.0
+        # https://github.com/Azure/azure-sdk-for-python/issues/31811
         existing_container = list(
             self.get_conn()
             .get_database_client(self.__get_database_name(database_name))
             .query_containers(
                 "SELECT * FROM r WHERE r.id=@id",
-                parameters=[json.dumps({"name": "@id", "value": 
collection_name})],
+                parameters=[{"name": "@id", "value": collection_name}],  # 
type: ignore[list-item]
             )
         )
         if not existing_container:
@@ -170,12 +171,14 @@ class AzureCosmosDBHook(BaseHook):
 
         # We need to check to see if this container already exists so we don't 
try
         # to create it twice
+        # The ignores below is due to typing bug in azure-cosmos 9.2.0
+        # https://github.com/Azure/azure-sdk-for-python/issues/31811
         existing_container = list(
             self.get_conn()
             .get_database_client(self.__get_database_name(database_name))
             .query_containers(
                 "SELECT * FROM r WHERE r.id=@id",
-                parameters=[json.dumps({"name": "@id", "value": 
collection_name})],
+                parameters=[{"name": "@id", "value": collection_name}],  # 
type: ignore[list-item]
             )
         )
 
@@ -190,10 +193,12 @@ class AzureCosmosDBHook(BaseHook):
         if database_name is None:
             raise AirflowBadRequest("Database name cannot be None.")
 
+        # The ignores below is due to typing bug in azure-cosmos 9.2.0
+        # https://github.com/Azure/azure-sdk-for-python/issues/31811
         existing_database = list(
             self.get_conn().query_databases(
                 "SELECT * FROM r WHERE r.id=@id",
-                parameters=[json.dumps({"name": "@id", "value": 
database_name})],
+                parameters=[{"name": "@id", "value": database_name}],  # type: 
ignore[list-item]
             )
         )
         if not existing_database:
@@ -208,10 +213,12 @@ class AzureCosmosDBHook(BaseHook):
 
         # We need to check to see if this database already exists so we don't 
try
         # to create it twice
+        # The ignores below is due to typing bug in azure-cosmos 9.2.0
+        # https://github.com/Azure/azure-sdk-for-python/issues/31811
         existing_database = list(
             self.get_conn().query_databases(
                 "SELECT * FROM r WHERE r.id=@id",
-                parameters=[json.dumps({"name": "@id", "value": 
database_name})],
+                parameters=[{"name": "@id", "value": database_name}],  # type: 
ignore[list-item]
             )
         )
 

Reply via email to