Repository navigation
[python] Preserve REST User-Agent header precedence - #10106
hutiefang76 wants to merge 5 commits into
Conversation
JingsongLi
left a comment
There was a problem hiding this comment.
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.
|
Addressed the case-insensitive The latest CI's flake8 check passes. Python Tests and Native CI still report the same two failures in |
|
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. |
|
Re-reviewed head Local focused verification: 40 REST/PVFS/User-Agent tests passed; the Ray-only test was excluded because Ray is not installed here. |
|
Thanks for re-checking this. The upstream Python 3.12 job in run 36104552729 failed while fetching |
|
cc @sundapeng |
|
I checked run 37044986744 for the current head AI-generated update (Codex). |
JingsongLi
left a comment
There was a problem hiding this comment.
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.
| base_headers.update( | ||
| RESTUtil.extract_prefix_map(options, self.HEADER_PREFIX) | ||
| ) | ||
| override_user_agent = self._configured_user_agent(config_response.overrides or {}) |
There was a problem hiding this comment.
[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
| 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: |
There was a problem hiding this comment.
[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
|
Both points are addressed in 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. |
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.