Skip to content

Restore the retryable trait in generated models - #946

Open
AlexDaines wants to merge 2 commits into
developfrom
adaines/restore-retryable-trait
Open

AlexDaines wants to merge 2 commits into
developfrom
adaines/restore-retryable-trait

Conversation

@AlexDaines

@AlexDaines AlexDaines commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Issue #, if available: N/A

Description of changes:

A generated client ignores the @retryable trait on a modeled error. Since #851, a client builds its model classes at runtime from the generated schemas. SchemaTraitFilterIndex doesn't keep the trait in those schemas, and the model builder in smithy_core._dynamic_models sets only fault on an error class. So unless #955 marks the error as retryable, it has is_retry_safe=None and StandardRetryStrategy makes one attempt.

For example, DynamoDB marks ReplicatedWriteConflictException as @retryable. With the client on develop in aws-sdk-python, ReplicatedWriteConflictException("x").is_retry_safe is None. With the released aws-sdk-dynamodb 0.12.0 it is True; the class source there has is_retry_safe: bool | None = True.

This change:

  • Keeps smithy.api#retryable in the generated schemas, in the Java generator and in the native generator (packages/smithy-python).
  • Adds RetryableTrait to smithy_core.traits.
  • Sets is_retry_safe = True on an error class whose shape is @retryable, and is_throttling_error = True for @retryable(throttling: true), as StructureGenerator.renderError does.

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.

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.
@AlexDaines
AlexDaines force-pushed the adaines/restore-retryable-trait branch from 0a6a7cb to 6ca3aa0 Compare November 17, 2026 12:50
@AlexDaines
AlexDaines marked this pull request as ready for review November 17, 2026 13:34
@AlexDaines
AlexDaines requested a review from a team as a code owner November 17, 2026 13:34
Comment thread codegen/build.gradle.kts

allprojects {
group = "software.amazon.smithy.python"
version = "0.7.0"

@kuhe kuhe Nov 17, 2026 •

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.

no bump is needed since we aren't releasing on maven.

it could cause problems with dev workspaces or (less likely) remote builds

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 29e02e7.

@jonathan343 jonathan343 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.

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

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.

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",

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.

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.

Suggested change
"type": "feature",
"type": "enhancement",

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.

3 participants