Skip to content

Commit

Permalink
fix(providers/azure): remove json.dumps when querying cosmos
Browse files Browse the repository at this point in the history
json.dumps leads to "azure.cosmos.exceptions.CosmosHttpResponseError: (BadRequest) Message: {"Errors":["Invalid query. Specified parameterized query JSON is malformed."]}"
  • Loading branch information
Lee-W committed Aug 25, 2023
1 parent 38f2737 commit 95c21ae
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions airflow/providers/microsoft/azure/hooks/cosmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"""
from __future__ import annotations

import json
import uuid
from typing import Any

Expand Down Expand Up @@ -150,7 +149,7 @@ def does_collection_exist(self, collection_name: str, database_name: str) -> boo
.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:
Expand All @@ -175,7 +174,7 @@ def create_collection(
.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]
)
)

Expand All @@ -193,7 +192,7 @@ def does_database_exist(self, database_name: str) -> bool:
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:
Expand All @@ -211,7 +210,7 @@ def create_database(self, database_name: str) -> None:
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]
)
)

Expand Down

0 comments on commit 95c21ae

Please sign in to comment.