Repository navigation
Conversation
| except Exception as error: | ||
| delay = state.accept(None, error) | ||
| output = None |
There was a problem hiding this comment.
since this also catches non-service errors, might be worth documenting that so callers will check last_error
There was a problem hiding this comment.
Documented this in the "Raises" section of the docstring.
There was a problem hiding this comment.
heads up: these use :param:. #981 switches the generated clients to Google style, so whichever merges second should switch these too
There was a problem hiding this comment.
Updated paginators and waiters to use Google style. Thanks for calling this out!
| for acceptor in self._definition.acceptors: | ||
| if acceptor.matcher.matches(self._request, output, error, self._operation): | ||
| break | ||
| else: | ||
| acceptor = None | ||
| state = ( | ||
| acceptor.state | ||
| if acceptor is not None | ||
| else "failure" | ||
| if error is not None | ||
| else "retry" | ||
| ) |
There was a problem hiding this comment.
accept() checks acceptors before _retry_delay() checks the deadline. This means a slow successful request can return after max_wait_time elapses. Is this intentional?
There was a problem hiding this comment.
Yes, this is intentional. The spec sets the last delay to remainingTime, so the final attempt starts at the limit and always finishes after it. Checking the deadline first would discard that response. smithy-java, smithy-rs, and smithy-ruby use the same order. This is made explicit in design/waiters.md under "Wait times and delays".
| def field(value: Any) -> Any: | ||
| if isinstance(value, dict): | ||
| return value.get(name) # pyright: ignore[reportUnknownMemberType, reportUnknownVariableType] | ||
| if value is None or isinstance(value, str | int | float | list | tuple): | ||
| return None | ||
| return getattr(value, attribute, None) |
There was a problem hiding this comment.
The waiter spec requires converting model values into JMESPath types. This returns Python values as bytes, datetime, and Decimal. Those values can miss on comparisons like is_number that accepts only int and float and stringEquals that accepts only str. Should a conversion happen before evaluating the path?
There was a problem hiding this comment.
Good catch! Reading model objects directly is intentional, so evaluating an expression doesn't need to convert the whole output before matching (this is important for endpoint resolution performance as well). But it means blob, timestamp, and bigDecimal values don't match the spec's data model. I checked all 1,086 output and inputOutput acceptors in the current AWS models and none of their paths reach one of these types, so no AWS waiter is affected today. A future model or a non-AWS model could still hit it.
I added a small fix that converts these values when a path reads them. Blobs become base64 strings, timestamps become epoch seconds, and bigDecimal becomes a float.
870eef7
870eef7 to
1b3141a
Compare
Description
Adds
wait_until_<waiter>methods to generated synchronous and asynchronous clients, implementing the design in #983. Each method polls its operation until an acceptor of the modeled waiter reports success or failure. It raisesWaiterTimeoutErroroncemax_wait_timepasses.Both code generators keep the
@waitabletrait in each operation's schema. The shared runtime,smithy_core.waiters.waitandsmithy_core.aio.waiters.wait_async, builds the operation's waiter definitions from that trait on first use and caches them on the schema. Each attempt runs through the normal client pipeline.This is stacked on
add-error-code-to-response-metadata.errorTypeacceptors use itsresponse_metadata.error_codeto match errors the model doesn't define, such as EC2's.Example
Methods return the output that matched a success acceptor. They return
Nonewhen the waiter succeeds on an error. Other outcomes raiseWaiterFailureErrororWaiterTimeoutError.Notes
max_wait_time,min_delay, andmax_delayare reserved on every operation input, likestop_on_same_token. Adding a waiter to a model doesn't rename input members.smithy_core._jmespathnow supports comparisons, filters,&&,||,!, literals, indexes, pipes,length(), andcontains(). Every waiter path in the AWS models compiles.GetItemwithItemReadyandItemDeletedwaiters. The Python features fixture gainsGetNotewithNoteSavedandNoteDeletedwaiters.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.