Skip to content

fix(bigtable): normalize scopes in _init_accelerator_config and _norm… - #19031

Open
mutianf wants to merge 1 commit into
bigtable-accelfrom
fix-accelerator-scope-normalization
Open

mutianf wants to merge 1 commit into
bigtable-accelfrom
fix-accelerator-scope-normalization

Conversation

@mutianf

@mutianf mutianf commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

…alize_scopes

Fixes b/578435999 🦕

@mutianf
mutianf requested a review from a team as a code owner November 10, 2026 04:00

@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 improves scope normalization in both the async and sync Bigtable clients by correctly handling lists of scopes that contain comma-separated values and leading/trailing whitespace. It also updates the accelerator configuration to use these normalized, sorted scopes and adds comprehensive unit tests to verify the new behavior. The review feedback suggests simplifying the generator expressions in _normalize_scopes by replacing commas with spaces and using split() without arguments, which would automatically strip whitespace and filter out empty strings.

Comment on lines +242 to +248
return frozenset(
part.strip()
for s in scopes
if isinstance(s, str)
for part in s.split(",")
if part.strip()
)

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

We can simplify the generator expression by replacing commas with spaces and using split() without arguments. This aligns the list-element parsing behavior with the string parsing behavior (which also splits on whitespace and commas), and leverages Python's optimized split() behavior to automatically strip whitespace and filter out empty strings, making the code cleaner and more robust.

    return frozenset(
        part
        for s in scopes
        if isinstance(s, str)
        for part in s.replace(",", " ").split()
    )

Comment on lines +180 to +188
return frozenset(
(
part.strip()
for s in scopes
if isinstance(s, str)
for part in s.split(",")
if part.strip()
)
)

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

We can simplify the generator expression by replacing commas with spaces and using split() without arguments. This aligns the list-element parsing behavior with the string parsing behavior, leverages Python's optimized split() behavior to automatically strip whitespace and filter out empty strings, and removes the redundant extra parentheses around the generator expression.

    return frozenset(
        part
        for s in scopes
        if isinstance(s, str)
        for part in s.replace(",", " ").split()
    )

This branch has not been deployed

No deployments
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