From 5f9a7c393461d89d8cbd177f28866ec149ffc86e Mon Sep 17 00:00:00 2001 From: David Blain Date: Tue, 23 Apr 2024 17:07:57 +0200 Subject: [PATCH 1/2] fix: Make sure the encoded_query_parameters function of the MSGraphTrigger only encodes the keys and not the values otherwise those will be encoded twice --- airflow/providers/microsoft/azure/triggers/msgraph.py | 2 +- .../microsoft/azure/triggers/test_msgraph.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/airflow/providers/microsoft/azure/triggers/msgraph.py b/airflow/providers/microsoft/azure/triggers/msgraph.py index c0e5ee85a0c4c..814a91f7c10a4 100644 --- a/airflow/providers/microsoft/azure/triggers/msgraph.py +++ b/airflow/providers/microsoft/azure/triggers/msgraph.py @@ -270,7 +270,7 @@ def normalize_url(self) -> str | None: def encoded_query_parameters(self) -> dict: if self.query_parameters: - return {quote(key): quote(str(value)) for key, value in self.query_parameters.items()} + return {quote(key): value for key, value in self.query_parameters.items()} return {} def request_information(self) -> RequestInformation: diff --git a/tests/providers/microsoft/azure/triggers/test_msgraph.py b/tests/providers/microsoft/azure/triggers/test_msgraph.py index 900d0875cd0f2..16b1f6c2eaf5e 100644 --- a/tests/providers/microsoft/azure/triggers/test_msgraph.py +++ b/tests/providers/microsoft/azure/triggers/test_msgraph.py @@ -132,6 +132,17 @@ def test_template_fields(self): for template_field in MSGraphTrigger.template_fields: getattr(trigger, template_field) + def test_encoded_query_parameters(self): + trigger = MSGraphTrigger( + url="myorg/admin/groups", + conn_id="msgraph_api", + query_parameters={"$expand": "reports,users,datasets,dataflows,dashboards", "$top": 5000} + ) + + actual = trigger.encoded_query_parameters() + + assert actual == {"%24expand": "reports,users,datasets,dataflows,dashboards", "%24top": 5000} + class TestResponseHandler: def test_handle_response_async(self): From e6d2b8ded8f7682098e0a25029bbeb255031e4a2 Mon Sep 17 00:00:00 2001 From: David Blain Date: Tue, 23 Apr 2024 20:11:12 +0200 Subject: [PATCH 2/2] refactor: Added missing coma --- tests/providers/microsoft/azure/triggers/test_msgraph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/providers/microsoft/azure/triggers/test_msgraph.py b/tests/providers/microsoft/azure/triggers/test_msgraph.py index 16b1f6c2eaf5e..a4e2c7f0fd598 100644 --- a/tests/providers/microsoft/azure/triggers/test_msgraph.py +++ b/tests/providers/microsoft/azure/triggers/test_msgraph.py @@ -136,7 +136,7 @@ def test_encoded_query_parameters(self): trigger = MSGraphTrigger( url="myorg/admin/groups", conn_id="msgraph_api", - query_parameters={"$expand": "reports,users,datasets,dataflows,dashboards", "$top": 5000} + query_parameters={"$expand": "reports,users,datasets,dataflows,dashboards", "$top": 5000}, ) actual = trigger.encoded_query_parameters()