Skip to content

[python] Preserve REST User-Agent header precedence - #10106

Open
hutiefang76 wants to merge 5 commits into
apache:masterfrom
hutiefang76:frank/paimon-8543-sdk-user-agent
Open

hutiefang76 wants to merge 5 commits into
apache:masterfrom
hutiefang76:frank/paimon-8543-sdk-user-agent

Conversation

@hutiefang76

@hutiefang76 hutiefang76 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Upstream now supplies the SDK User-Agent format. This PR preserves the remaining header precedence behavior: default < client headers < per-request overrides, with case-insensitive User-Agent matching and one canonical prepared header.

Fixes #8543.

Validation: 42 tests plus two subtests passed; new prepared-request regressions fail on the prior implementation. Existing REST, OSS and token loader coverage and scoped Flake8 checks passed. No dependency changes.

Updated with Codex assistance; the diff and regression evidence were reviewed.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linked #8543 is a concrete observability need, and the default version string now reaches real REST requests. I ran the four affected Python suites: 41 tests passed after allowing the local REST test server to bind its port. I also checked the prepared HTTP request, not only the in-memory header map.

[P2] Preserve explicitly configured User-Agent regardless of header casing. HTTP header names are case-insensitive, but base_headers.setdefault("User-Agent", ...) and PVFS's options.contains("header.User-Agent") are exact-case checks. With a valid configuration header.user-agent=custom-client/1.0, RESTApi keeps both user-agent: custom-client/1.0 and User-Agent: PyPaimon/...; requests.Session.prepare_request(...) sends the latter, silently overriding the explicit value. PVFS also inserts both keys. This violates the preservation requirement in #8543. Please detect existing User-Agent headers case-insensitively (also after REST config merge) and add a test that inspects a prepared request for a lowercase configured key.

Requirement fit: SUPPORTED. Requesting changes for the configuration contract before production use.

@hutiefang76

Copy link
Copy Markdown
Contributor Author

Addressed the case-insensitive User-Agent feedback in ca90868bf. The new tests inspect the prepared HTTP request for lowercase client headers, including config merge/override behavior, and cover the PVFS option path.

The latest CI's flake8 check passes. Python Tests and Native CI still report the same two failures in interval_partition_test.py::test_signed_zero_key_ranges_keep_versions_in_one_split (SimpleNamespace lacks path_factory). That test file is unchanged by this PR and is identical on current origin/master; the PR changes only the User-Agent files. I am keeping this CI failure visible rather than treating the PR as green.

@hutiefang76

Copy link
Copy Markdown
Contributor Author

Synced with master in d615576 to pick up the merged #10169 fix for the unrelated interval-partition CI failure. The targeted User-Agent, build-info, REST, PVFS and interval-partition tests pass locally (39 tests), and flake8 passes with the project config. The local Ray integration case was excluded because Ray is not installed. Fresh CI is now pending.

@JingsongLi

Copy link
Copy Markdown
Contributor

Re-reviewed head d615576 for production. The case-insensitive User-Agent handling now preserves a lowercase caller value on the actual prepared REST request, including after catalog defaults/overrides merge; PVFS also leaves a caller-supplied header intact. This addresses my earlier P2 finding. The default header carries the SDK and Python versions, giving the linked #8543 a concrete observability benefit.

Local focused verification: 40 REST/PVFS/User-Agent tests passed; the Ray-only test was excluded because Ray is not installed here. git diff --check passed. Native CI and Python 3.6/3.7/3.10/3.11/3.13 passed. Python 3.12 CI failed while downloading maven-settings-builder:3.0.4 from Maven Central (Connection reset), before running tests, so it needs a rerun; this is an infrastructure failure rather than a code finding. I found no remaining production blocker in this PR.

@hutiefang76

Copy link
Copy Markdown
Contributor Author

Thanks for re-checking this. The upstream Python 3.12 job in run 36104552729 failed while fetching maven-settings-builder:3.0.4, before the tests started. I tried to rerun that failed job, but GitHub requires repository admin access. Could someone with workflow access rerun it when convenient?

@hutiefang76 hutiefang76 changed the title [python] Add SDK version to REST User-Agent [python] Preserve REST User-Agent header precedence Oct 2, 2026
@JingsongLi

Copy link
Copy Markdown
Contributor

cc @sundapeng

@hutiefang76

Copy link
Copy Markdown
Contributor Author

I checked run 37044986744 for the current head 73cf38daa: Python 3.12 completed successfully on October 2. The job log records 6,519 passed, 223 skipped and 1,379 deselected in the main pytest invocation, with the REST/User-Agent suites executed. The overall CI run also passed, so the earlier Python 3.12 dependency-download failure is resolved.

AI-generated update (Codex).

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I compared the outgoing REST requests from this revision with the Python baseline and Java. The inline comments cover two regressions in resolving the User-Agent after /v1/config.

Comment thread paimon-python/pypaimon/api/rest_api.py Outdated
base_headers.update(
RESTUtil.extract_prefix_map(options, self.HEADER_PREFIX)
)
override_user_agent = self._configured_user_agent(config_response.overrides or {})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Honor null overrides that clear a default User-Agent

With no client User-Agent, a /v1/config response with defaults: {"header.User-Agent": "default/1"} and overrides: {"header.User-Agent": null} removes the option in ConfigResponse.merge. The separate lookup skips that null and restores default/1 from the raw defaults. I verified that the next request sends default/1 and a catalog reloaded from the merged options sends the generated SDK header. Both the Python baseline and Java send the generated header for both requests.

Please preserve the removal when resolving the header and add a regression test for a same-key null override with no client header. Existing ConfigResponse test for clearing a default

Comment thread paimon-python/pypaimon/api/rest_api.py Outdated
def _configured_user_agent(cls, options: Dict[str, str]) -> Optional[str]:
user_agent_value = None
for key, value in options.items():
if key.lower() == (cls.HEADER_PREFIX + "User-Agent").lower() and value is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep the header. configuration prefix case-sensitive

Lowercasing the full key makes Header.User-Agent eligible as a REST header. With the client option header.User-Agent=client/1 and a server override Header.User-Agent=alias/1, the next request sends alias/1. Java and the Python baseline both require the literal header. prefix and send client/1 for this input.

Please match the configuration prefix exactly and compare the HTTP header name case-insensitively. Java prefix handling

@hutiefang76

Copy link
Copy Markdown
Contributor Author

Both points are addressed in b1170ef5880b. After config merging, a same-key null override now clears the default User-Agent, so the next request and a catalog restored from the merged options both use the generated SDK header. The configuration prefix must be exactly header.. The HTTP header name still matches case-insensitively.

Both new regressions fail on the previous revision and pass with the fix. All 62 focused tests passed on the PR branch, and all 23 User-Agent tests passed on the local copy of GitHub's merge ref with the patch applied. Scoped Flake8 passed. DeepSeek and Codex assisted implementation and review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add sdk version information to REST User-Agent

2 participants