From 4dde424052df0ce97607f595a5cf4eded005a97f Mon Sep 17 00:00:00 2001 From: Patrick Ogenstad Date: Thu, 28 Aug 2025 13:36:57 +0200 Subject: [PATCH] Respect default branch for client.query_gql_query() --- changelog/236.fixed.md | 1 + infrahub_sdk/client.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 changelog/236.fixed.md diff --git a/changelog/236.fixed.md b/changelog/236.fixed.md new file mode 100644 index 00000000..510c0a58 --- /dev/null +++ b/changelog/236.fixed.md @@ -0,0 +1 @@ +Respect default branch for client.query_gql_query() and client.set_context_properties() diff --git a/infrahub_sdk/client.py b/infrahub_sdk/client.py index 4a6ad81b..8ace112a 100644 --- a/infrahub_sdk/client.py +++ b/infrahub_sdk/client.py @@ -209,7 +209,7 @@ def set_context_properties( delete_unused_nodes=delete_unused_nodes, group_type=group_type, group_params=group_params, - branch=branch, + branch=branch or self.default_branch, ) def _graphql_url( @@ -1103,13 +1103,13 @@ async def query_gql_query( ) -> dict: url = f"{self.address}/api/query/{name}" url_params = copy.deepcopy(params or {}) + url_params["branch"] = branch_name or self.default_branch + headers = copy.copy(self.headers or {}) if self.insert_tracker and tracker: headers["X-Infrahub-Tracker"] = tracker - if branch_name: - url_params["branch"] = branch_name if at: url_params["at"] = at @@ -2242,13 +2242,13 @@ def query_gql_query( ) -> dict: url = f"{self.address}/api/query/{name}" url_params = copy.deepcopy(params or {}) + url_params["branch"] = branch_name or self.default_branch + headers = copy.copy(self.headers or {}) if self.insert_tracker and tracker: headers["X-Infrahub-Tracker"] = tracker - if branch_name: - url_params["branch"] = branch_name if at: url_params["at"] = at if subscribers: