Repository navigation
Restore the retryable trait in generated models - #946
AlexDaines wants to merge 2 commits into
Conversation
Generated clients build their model classes at runtime from the generated schemas. The schema trait filter didn't keep the retryable trait, and the model builder set only the fault of an error class, so a modeled error whose shape is retryable was not retry-safe. The generated schemas now keep the trait, and the model builder sets is_retry_safe, and is_throttling_error for a throttling error, as StructureGenerator does for a generated class.
0a6a7cb to
6ca3aa0
Compare
|
|
||
| allprojects { | ||
| group = "software.amazon.smithy.python" | ||
| version = "0.7.0" |
There was a problem hiding this comment.
no bump is needed since we aren't releasing on maven.
it could cause problems with dev workspaces or (less likely) remote builds
jonathan343
left a comment
There was a problem hiding this comment.
Thanks for adding this @AlexDaines!
I have a few minor comments, but this looks good otherwise.
I investigated the failing CI job and it looks like our secrets-manager integration test in aws-sdk-python might be failing due to a throttling error. These are now retried after #955 which I don't think was merged when this job ran. I'm gonna retry the job manually. Our job merges w/ latest from develop, so it should pick it up without a rebase.
| """Whether the error is a throttling error.""" | ||
| if self.document_value is None: | ||
| return False | ||
| return self.document_value.get("throttling", False) # type: ignore |
There was a problem hiding this comment.
We should avoid ignores when the type checker can be satisfied, especially a bare # type: ignore. A bare ignore hides every error on the line, including future ones. I know other traits in this file do this, but I'm just catching it now and don't want to add another.
I prefer we do something like the following example instead:
@property
def throttling(self) -> bool:
"""Whether the error is a throttling error."""
if not isinstance(self.document_value, Mapping):
return False
return self.document_value.get("throttling") is True| @@ -0,0 +1,4 @@ | |||
| { | |||
| "type": "feature", | |||
There was a problem hiding this comment.
I think classifying this as an enhancement makes more sense. A feature makes smithy-core minor bump to 0.14.0. Every dependent pins smithy-core~=0.13.0, so they would all need new releases too. That doesn't make sense here, since only smithy-core uses RetryableTrait.
| "type": "feature", | |
| "type": "enhancement", |
Issue #, if available: N/A
Description of changes:
A generated client ignores the
@retryabletrait on a modeled error. Since #851, a client builds its model classes at runtime from the generated schemas.SchemaTraitFilterIndexdoesn't keep the trait in those schemas, and the model builder insmithy_core._dynamic_modelssets onlyfaulton an error class. So unless #955 marks the error as retryable, it hasis_retry_safe=NoneandStandardRetryStrategymakes one attempt.For example, DynamoDB marks
ReplicatedWriteConflictExceptionas@retryable. With the client ondevelopin aws-sdk-python,ReplicatedWriteConflictException("x").is_retry_safeisNone. With the releasedaws-sdk-dynamodb0.12.0 it isTrue; the class source there hasis_retry_safe: bool | None = True.This change:
smithy.api#retryablein the generated schemas, in the Java generator and in the native generator (packages/smithy-python).RetryableTraittosmithy_core.traits.is_retry_safe = Trueon an error class whose shape is@retryable, andis_throttling_error = Truefor@retryable(throttling: true), asStructureGenerator.renderErrordoes.The tests cover the model builder with
@retryable,@retryable(throttling: true), and@retryable(throttling: false), the trait in a schema that the Java generator writes, and the flags on an error class in the committed output of both generators.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.