You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by yz...@apache.org on 2026/10/14 17:20:23 UTC

(polaris) branch main updated: Stop HEADER env from being ignored (#5782)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 11c0ea4037 Stop HEADER env from being ignored (#5782)
11c0ea4037 is described below

commit 11c0ea40374b306bda7facfffacbd46b61a0cbab
Author: Alex Stephen <13...@users.noreply.github.com>
AuthorDate: Wed Oct 14 10:20:16 2026 -0700

    Stop HEADER env from being ignored (#5782)
---
 .../apache_polaris/cli/api_client_builder.py       |  4 +++-
 client/python/apache_polaris/cli/options/parser.py |  3 +--
 client/python/tests/test_api_client_builder.py     | 27 ++++++++++++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/client/python/apache_polaris/cli/api_client_builder.py b/client/python/apache_polaris/cli/api_client_builder.py
index c616e4d55f..9968af639c 100644
--- a/client/python/apache_polaris/cli/api_client_builder.py
+++ b/client/python/apache_polaris/cli/api_client_builder.py
@@ -29,6 +29,7 @@ from apache_polaris.cli.constants import (
     REALM_ENV,
     HEADER_ENV,
     Arguments,
+    DEFAULT_HEADER,
     DEFAULT_HOSTNAME,
     DEFAULT_PORT,
     DEFAULT_SCHEME,
@@ -125,11 +126,12 @@ class BuilderConfig:
         return realms
 
     @cached_property
-    def header(self) -> Optional[str]:
+    def header(self) -> str:
         return (
             self.options.header
             or os.getenv(HEADER_ENV)
             or self.profile.get(Arguments.HEADER)
+            or DEFAULT_HEADER
         )
 
 
diff --git a/client/python/apache_polaris/cli/options/parser.py b/client/python/apache_polaris/cli/options/parser.py
index 2f99f75da6..794e8b1bc8 100644
--- a/client/python/apache_polaris/cli/options/parser.py
+++ b/client/python/apache_polaris/cli/options/parser.py
@@ -20,7 +20,7 @@ import argparse
 from typing import List, Optional, Dict, Any, Union
 
 from apache_polaris import __version__
-from apache_polaris.cli.constants import Arguments, DEFAULT_HEADER, Hints
+from apache_polaris.cli.constants import Arguments, Hints
 from apache_polaris.cli.exceptions import CliError
 from apache_polaris.cli.options.option_tree import OptionTree, Option, Argument
 
@@ -78,7 +78,6 @@ class Parser(object):
             Arguments.HEADER,
             str,
             hint="Context header name (default: Polaris-Realm)",
-            default=DEFAULT_HEADER,
         ),
         Argument(Arguments.PROFILE, str, hint="Polaris profile name"),
         Argument(Arguments.PROXY, str, hint="Proxy URL"),
diff --git a/client/python/tests/test_api_client_builder.py b/client/python/tests/test_api_client_builder.py
index 71ab79df9c..0f31c21a04 100644
--- a/client/python/tests/test_api_client_builder.py
+++ b/client/python/tests/test_api_client_builder.py
@@ -18,11 +18,13 @@
 #
 
 import json
+import os
 import unittest
 from argparse import Namespace
 from unittest.mock import MagicMock, patch
 
 from apache_polaris.cli.api_client_builder import ApiClientBuilder, BuilderConfig
+from apache_polaris.cli.constants import DEFAULT_HEADER, HEADER_ENV
 from apache_polaris.cli.exceptions import CliError, CLI_ERROR_EXIT_CODE
 
 
@@ -249,5 +251,30 @@ class TestBuilderConfigBaseUrl(unittest.TestCase):
         self.assertEqual(cfg.base_url, "https://localhost:443")
 
 
+class TestBuilderConfigHeader(unittest.TestCase):
+    def test_header_precedence(self) -> None:
+        cases = [
+            (None, None, None, DEFAULT_HEADER),
+            (None, None, "X-Profile", "X-Profile"),
+            (None, "X-Env", "X-Profile", "X-Env"),
+            ("X-Option", "X-Env", "X-Profile", "X-Option"),
+        ]
+        for option, env, profile, expected in cases:
+            with self.subTest(option=option, env=env, profile=profile):
+                opts = _builder_options()
+                opts.header = option
+                opts.profile = "prod"
+                with (
+                    patch.dict(
+                        os.environ, {HEADER_ENV: env} if env else {}, clear=True
+                    ),
+                    patch(
+                        "apache_polaris.cli.api_client_builder.load_profiles",
+                        return_value={"prod": {"header": profile}},
+                    ),
+                ):
+                    self.assertEqual(BuilderConfig(opts).header, expected)
+
+
 if __name__ == "__main__":
     unittest.main()