Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pyproject.toml": "321817c332d0760a244c76bedaf7a21c70d92254ab9458b533f347c3860d4db4",
"src/my_handwritten_json_model/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd",
"src/my_handwritten_json_model/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"src/my_handwritten_json_model/_private/schemas.py": "1a1bbc8bafb312919b994a51fc106c76578e1cffa9032fe9bbd9a02c0b102426",
"src/my_handwritten_json_model/_private/schemas.py": "d6a88206b0288f028d923a590d97acb21efc6f5d6d29dacc1393068063ab4435",
"src/my_handwritten_json_model/models.py": "c7d9575479a8a6a3580871da76345de34c6ca18a977f271fcf9bd62801715700",
"src/my_handwritten_json_model/models.pyi": "8f59462ef2d242ae24b24bbcdb082aa05576aab445d2fa2bc9ae3a9194399bdb",
"src/my_handwritten_json_model/py.typed": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from types import MappingProxyType

from smithy_core._schema_compact import StaticSchema

n0 = "smithy.python.tests.handwritten.json"
Expand All @@ -22,20 +24,21 @@
_s18 = "server"
_s19 = "ThrottlingEvent"
_s20 = "client"
_s21 = "TradeEvents"
_s22 = "smithy.api#streaming"
_s23 = "alpha"
_s24 = "beta"
_s25 = "gamma"
_s26 = "delta"
_s27 = "throttle"
_s28 = "TradeEventStreamInput"
_s29 = "smithy.api#input"
_s30 = "sessionId"
_s31 = "events"
_s32 = "TradeEventStreamOutput"
_s33 = "smithy.api#output"
_s34 = "greeting"
_s21 = "smithy.api#retryable"
_s22 = "TradeEvents"
_s23 = "smithy.api#streaming"
_s24 = "alpha"
_s25 = "beta"
_s26 = "gamma"
_s27 = "delta"
_s28 = "throttle"
_s29 = "TradeEventStreamInput"
_s30 = "smithy.api#input"
_s31 = "sessionId"
_s32 = "events"
_s33 = "TradeEventStreamOutput"
_s34 = "smithy.api#output"
_s35 = "greeting"

ALPHA: StaticSchema = (
18,
Expand Down Expand Up @@ -95,34 +98,34 @@
18,
n0,
_s19,
{_s17: _s20},
{_s17: _s20, _s21: MappingProxyType({"throttling": True})},
(_s9,),
((3, 0),),
)

TRADE_EVENTS: StaticSchema = (
19,
n0,
_s21,
{_s22: None},
(_s23, _s24, _s25, _s26, _s27),
_s22,
{_s23: None},
(_s24, _s25, _s26, _s27, _s28),
((ALPHA, 0), (-1, 0), (GAMMA, 0), (DIFFERENT_SHAPE_NAME, 0), (THROTTLING_EVENT, 0)),
)

TRADE_EVENT_STREAM_INPUT: StaticSchema = (
18,
n0,
_s28,
{_s29: None},
(_s30, _s31),
_s29,
{_s30: None},
(_s31, _s32),
((3, 0), (TRADE_EVENTS, 0)),
)

TRADE_EVENT_STREAM_OUTPUT: StaticSchema = (
18,
n0,
_s32,
{_s33: None},
(_s34, _s31),
_s33,
{_s34: None},
(_s35, _s32),
((3, 0), (TRADE_EVENTS, 0)),
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"pyproject.toml": "88e01463cc0d24fd7ab8bf99d96f0fe3b3f031f3348fc1c371c533c891184053",
"src/my_handwritten_model/__init__.py": "619a033058229139a02f912a44a6b8997fb35c5af6736d09edd49927876a49dd",
"src/my_handwritten_model/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"src/my_handwritten_model/_private/schemas.py": "dc76275b338c278172c30166e40c964952fdb5e9ae06f49dff33a37a58a39ff7",
"src/my_handwritten_model/_private/schemas.py": "c3078c36bcc780fd15ae3135bc22e8de2415713dadb2b1151a81fd0fd2ba5d0b",
"src/my_handwritten_model/models.py": "ca3c2b4d5dab0e7da762ec0feceaeda02fd0656fdeb161e0417686a8b4279e24",
"src/my_handwritten_model/models.pyi": "a01e010947193acad3008148301f76d2e5de0dbbe09b149f325d64582b0815a3",
"src/my_handwritten_model/py.typed": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from types import MappingProxyType

from smithy_core._schema_compact import StaticSchema

n0 = "smithy.python.tests.handwritten"
Expand Down Expand Up @@ -47,16 +49,17 @@
_s43 = "subscriptionId"
_s44 = "ThrottlingEvent"
_s45 = "client"
_s46 = "TradeEvents"
_s47 = "alpha"
_s48 = "beta"
_s49 = "gamma"
_s50 = "delta"
_s51 = "throttle"
_s52 = "TradeEventStreamInput"
_s53 = "sessionId"
_s54 = "TradeEventStreamOutput"
_s55 = "greeting"
_s46 = "smithy.api#retryable"
_s47 = "TradeEvents"
_s48 = "alpha"
_s49 = "beta"
_s50 = "gamma"
_s51 = "delta"
_s52 = "throttle"
_s53 = "TradeEventStreamInput"
_s54 = "sessionId"
_s55 = "TradeEventStreamOutput"
_s56 = "greeting"

ALPHA: StaticSchema = (
18,
Expand Down Expand Up @@ -206,34 +209,34 @@
18,
n0,
_s44,
{_s35: _s45},
{_s35: _s45, _s46: MappingProxyType({"throttling": True})},
(_s9,),
((3, 0),),
)

TRADE_EVENTS: StaticSchema = (
19,
n0,
_s46,
_s47,
{_s24: None},
(_s47, _s48, _s49, _s50, _s51),
(_s48, _s49, _s50, _s51, _s52),
((ALPHA, 0), (-1, 0), (GAMMA, 0), (DIFFERENT_SHAPE_NAME, 0), (THROTTLING_EVENT, 0)),
)

TRADE_EVENT_STREAM_INPUT: StaticSchema = (
18,
n0,
_s52,
_s53,
{_s28: None},
(_s53, _s30),
(_s54, _s30),
((3, 0), (TRADE_EVENTS, 0)),
)

TRADE_EVENT_STREAM_OUTPUT: StaticSchema = (
18,
n0,
_s54,
_s55,
{_s32: None},
(_s55, _s30),
(_s56, _s30),
((3, 0), (TRADE_EVENTS, 0)),
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
_se = "server"
_TE = "ThrottlingEvent"
_c = "client"
_sm = "smithy.api#retryable"
_TEr = "TradeEvents"
_sm = "smithy.api#streaming"
_smi = "smithy.api#streaming"
_a = "alpha"
_b = "beta"
_g = "gamma"
_d = "delta"
_th = "throttle"
_TESI = "TradeEventStreamInput"
_smi = "smithy.api#input"
_smit = "smithy.api#input"
_sI = "sessionId"
_e = "events"
_TESO = "TradeEventStreamOutput"
_smit = "smithy.api#output"
_smith = "smithy.api#output"
_gr = "greeting"
_TES = "TradeEventStream"
_MHJM = "MyHandwrittenJsonModel"
Expand All @@ -64,13 +65,20 @@

STREAM_SERVICE_ERROR: StaticSchema = (18, n0, _SSE, {_s: _se}, (_me,), ((3, 0),))

THROTTLING_EVENT: StaticSchema = (18, n0, _TE, {_s: _c}, (_me,), ((3, 0),))
THROTTLING_EVENT: StaticSchema = (
18,
n0,
_TE,
{_s: _c, _sm: MappingProxyType({"throttling": True})},
(_me,),
((3, 0),),
)

TRADE_EVENTS: StaticSchema = (
19,
n0,
_TEr,
{_sm: None},
{_smi: None},
(_a, _b, _g, _d, _th),
((ALPHA, 0), (-1, 0), (GAMMA, 0), (DIFFERENT_SHAPE_NAME, 0), (THROTTLING_EVENT, 0)),
)
Expand All @@ -79,7 +87,7 @@
18,
n0,
_TESI,
{_smi: None},
{_smit: None},
(_sI, _e),
((3, 0), (TRADE_EVENTS, 0)),
)
Expand All @@ -88,7 +96,7 @@
18,
n0,
_TESO,
{_smit: None},
{_smith: None},
(_gr, _e),
((3, 0), (TRADE_EVENTS, 0)),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
_se = "server"
_TE = "ThrottlingEvent"
_cl = "client"
_smith = "smithy.api#retryable"
_TEr = "TradeEvents"
_a = "alpha"
_b = "beta"
Expand Down Expand Up @@ -169,7 +170,14 @@

STREAM_SERVICE_ERROR: StaticSchema = (18, n0, _SSE, {_smit: _se}, (_me,), ((3, 0),))

THROTTLING_EVENT: StaticSchema = (18, n0, _TE, {_smit: _cl}, (_me,), ((3, 0),))
THROTTLING_EVENT: StaticSchema = (
18,
n0,
_TE,
{_smit: _cl, _smith: MappingProxyType({"throttling": True})},
(_me,),
((3, 0),),
)

TRADE_EVENTS: StaticSchema = (
19,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ def upload_city_image(
assertTrue(syncConfig.contains("from ._private.endpoints import BDD"));
assertTrue(schemas.contains("smithy.api#longPoll"));
assertTrue(schemas.contains("\"timeoutMillis\": 20000"));
assertTrue(schemas.contains("smithy.api#retryable"));
assertTrue(schemas.contains("\"throttling\": True"));
}

@Test
Expand Down
8 changes: 8 additions & 0 deletions codegen/core/src/it/resources/META-INF/smithy/main.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ operation GetCity {
errors: [
NoSuchResource
EmptyError
ThrottlingError
]
}

Expand Down Expand Up @@ -348,6 +349,13 @@ apply NoSuchResource @httpResponseTests([
@httpError(400)
structure EmptyError {}

@error("client")
@retryable(throttling: true)
@httpError(429)
structure ThrottlingError {
message: String
}

// The paginated trait indicates that the operation may
// return truncated results.
@readonly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import software.amazon.smithy.model.traits.RequestCompressionTrait;
import software.amazon.smithy.model.traits.RequiredTrait;
import software.amazon.smithy.model.traits.RequiresLengthTrait;
import software.amazon.smithy.model.traits.RetryableTrait;
import software.amazon.smithy.model.traits.SensitiveTrait;
import software.amazon.smithy.model.traits.SparseTrait;
import software.amazon.smithy.model.traits.StreamingTrait;
Expand Down Expand Up @@ -117,6 +118,7 @@ public final class SchemaTraitFilterIndex implements KnowledgeIndex {
StreamingTrait.ID,
EndpointTrait.ID,
ErrorTrait.ID,
RetryableTrait.ID, // runtime sets the retry defaults of the error class
RequiresLengthTrait.ID,
EventHeaderTrait.ID,
EventPayloadTrait.ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "bugfix",
"description": "Fixed modeled errors with the `@retryable` trait not being retry-safe in generated clients."
}
Original file line number Diff line number Diff line change
@@ -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",

"description": "Added `RetryableTrait` to `smithy_core.traits`."
}
6 changes: 6 additions & 0 deletions packages/smithy-core/src/smithy_core/_dynamic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
ErrorTrait,
IdempotencyTokenTrait,
RequiredTrait,
RetryableTrait,
SensitiveTrait,
SparseTrait,
StreamingTrait,
Expand Down Expand Up @@ -451,6 +452,11 @@ def _build_struct(self, name: str, schema: Schema) -> type:
fields.append(
("fault", str | None, _field(default=error_trait.fault.value))
)
retryable_trait = schema.get_trait(RetryableTrait)
if retryable_trait is not None:
fields.append(("is_retry_safe", bool | None, _field(default=True)))
if retryable_trait.throttling:
fields.append(("is_throttling_error", bool, _field(default=True)))
bases: tuple[type, ...] = (self._error_base(),) if is_error else ()
# Operation outputs carry a non-modeled response_metadata attribute, excluded
# from eq and repr. Errors inherit it from ModeledError instead.
Expand Down
16 changes: 16 additions & 0 deletions packages/smithy-core/src/smithy_core/traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"OperationContextParamsTrait",
"RequiredTrait",
"RequiresLengthTrait",
"RetryableTrait",
"RpcV2CborTrait",
"RpcV2JsonTrait",
"SensitiveTrait",
Expand Down Expand Up @@ -194,6 +195,21 @@ def __init__(self, value: "DocumentValue | DynamicTrait" = None):
object.__setattr__(self, "fault", ErrorFault(self.document_value))


@dataclass(init=False, frozen=True)
class RetryableTrait(Trait, id=ShapeID("smithy.api#retryable")):
"""Indicates that an error may be retried by the client."""

def __post_init__(self) -> None:
assert self.document_value is None or isinstance(self.document_value, Mapping)

@property
def throttling(self) -> bool:
"""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



@dataclass(init=False, frozen=True)
class RequiredTrait(Trait, id=ShapeID("smithy.api#required")):
"""Marks a member as required."""
Expand Down
Loading
Loading