Skip to content

feat(bigtable): support custom retry functions in mutate_rows shim - #18281

Closed
daniel-sanche wants to merge 5 commits into
shim/08-bulk-mutate-rowsfrom
shim/08.5-mutate-rows-retry
Closed

feat(bigtable): support custom retry functions in mutate_rows shim#18281
daniel-sanche wants to merge 5 commits into
shim/08-bulk-mutate-rowsfrom
shim/08.5-mutate-rows-retry

Conversation

@daniel-sanche

Copy link
Copy Markdown
Contributor

Building off of #18195 to add support for Retry object on_error and predicate. Instead of being ignored, these methods are sent through into the internal retry object

For predicate, that means retries will fail if the default predicate triggers, or the user-specified one

@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 introduces support for legacy client shims in the mutate_rows operation by adding optional shim_predicate and shim_on_error callbacks. These callbacks are integrated into the retry tracking mechanism in both synchronous and asynchronous implementations, and corresponding unit tests have been added. The reviewer suggests defensively using getattr when accessing attributes on the retry and DEFAULT_RETRY objects to prevent potential AttributeErrors if duck-typed or custom objects are passed.

Comment on lines +762 to +775
if retry is None or getattr(retry, "deadline", None) == 0:
operation_timeout = TABLE_DEFAULT.MUTATE_ROWS
retryable_errors = []
else:
operation_timeout = retry.deadline
operation_timeout = (
retry.deadline
if retry.deadline is not None
else TABLE_DEFAULT.MUTATE_ROWS
)
if (
getattr(retry, "_predicate", None) is not None
and retry._predicate is not DEFAULT_RETRY._predicate
):
shim_predicate = retry._predicate

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

To prevent potential AttributeErrors when retry or DEFAULT_RETRY are duck-typed or custom objects that do not implement all attributes (such as deadline or _predicate), we should use getattr defensively for all attribute accesses on these objects.

Suggested change
if retry is None or getattr(retry, "deadline", None) == 0:
operation_timeout = TABLE_DEFAULT.MUTATE_ROWS
retryable_errors = []
else:
operation_timeout = retry.deadline
operation_timeout = (
retry.deadline
if retry.deadline is not None
else TABLE_DEFAULT.MUTATE_ROWS
)
if (
getattr(retry, "_predicate", None) is not None
and retry._predicate is not DEFAULT_RETRY._predicate
):
shim_predicate = retry._predicate
if retry is None or getattr(retry, "deadline", None) == 0:
operation_timeout = TABLE_DEFAULT.MUTATE_ROWS
retryable_errors = []
else:
deadline = getattr(retry, "deadline", None)
operation_timeout = (
deadline
if deadline is not None
else TABLE_DEFAULT.MUTATE_ROWS
)
retry_predicate = getattr(retry, "_predicate", None)
default_predicate = getattr(DEFAULT_RETRY, "_predicate", None)
if retry_predicate is not None and retry_predicate is not default_predicate:
shim_predicate = retry_predicate

@daniel-sanche

Copy link
Copy Markdown
Contributor Author

Actually, doing more research, it looks like on_error and predicate were never truly supported in the client, so we can avoid this change

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