feat(bigtable): support custom retry functions in mutate_rows shim - #18281
feat(bigtable): support custom retry functions in mutate_rows shim#18281daniel-sanche wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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 |
|
Actually, doing more research, it looks like on_error and predicate were never truly supported in the client, so we can avoid this change |
Building off of #18195 to add support for Retry object
on_errorandpredicate. Instead of being ignored, these methods are sent through into the internal retry objectFor predicate, that means retries will fail if the default predicate triggers, or the user-specified one