Skip to content

fix(api-core): address PR review comments for requests.py and test_requests - #17795

Closed
hebaalazzeh wants to merge 1 commit into
mainfrom
fix/requests-optional-id
Closed

fix(api-core): address PR review comments for requests.py and test_requests#17795
hebaalazzeh wants to merge 1 commit into
mainfrom
fix/requests-optional-id

Conversation

@hebaalazzeh

Copy link
Copy Markdown
Contributor

Description

This PR addresses code review feedback regarding edge cases and test coverage in requests.py and test_requests.py:

  1. requests.py: Updated fallback logic for proto-plus messages/other objects when is_proto3_optional=True from if not getattr(...) to if getattr(...) is None. This distinguishes missing fields from fields explicitly set to empty values (e.g., ""), matching the dictionary handling behavior.
  2. test_requests.py: Removed the unused __contains__ mock helper methods from MockRequest and MockValueErrorRequest since the helper uses the in operator only for dictionaries.
  3. test_requests.py: Added parameterized test cases for is_proto3_optional=True with explicit empty string values "" to verify they are preserved and not overwritten.
  4. test_requests.py: Changed test assertions to use re.fullmatch instead of re.match to guarantee strict UUID format validation.

@hebaalazzeh
hebaalazzeh marked this pull request as ready for review July 20, 2026 22:57
@hebaalazzeh
hebaalazzeh requested a review from a team as a code owner July 20, 2026 22:57

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request modifies setup_request_id to check if a field is explicitly None rather than falsy (such as an empty string) when handling proto-plus or other objects, preventing an empty string from being overwritten by a new UUID. Corresponding test cases for empty strings were added, unused mock methods were removed, and re.match was updated to re.fullmatch in the tests. The reviewer suggests extending the test coverage by adding a test case for MockProtoRequest with an empty string to ensure standard protobuf messages are also verified.

# MockRequest cases
(MockRequest(), True, "uuid"),
(MockRequest(request_id="already_set"), True, "already_set"),
(MockRequest(request_id=""), True, ""),

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.

medium

While adding a test case for MockRequest with an explicit empty string when is_proto3_optional=True is great, we should also add a corresponding test case for MockProtoRequest to ensure standard protobuf messages (which implement HasField) are also covered and behave correctly under this scenario. Please consider adding (MockProtoRequest(request_id=""), True, "") and the corresponding ID "proto3_optional_explicit_empty_proto" to the ids list.

@hebaalazzeh
hebaalazzeh deleted the fix/requests-optional-id branch July 20, 2026 22:58
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.

1 participant