Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamp deserialization doesn't take target traits into account #714

Closed
ianbotsf opened this issue Oct 10, 2022 · 0 comments
Closed

Timestamp deserialization doesn't take target traits into account #714

ianbotsf opened this issue Oct 10, 2022 · 0 comments
Assignees
Labels
bug This issue is a bug.

Comments

@ianbotsf
Copy link
Contributor

Describe the bug

Smithy models support the timestampFormat trait on both timestamp target shapes and member shapes which target timestamp shapes. Currently, deserializer codegen only checks the member for the timestampFormat trait and ignores the trait on targets. This leads to incorrect serialization of timestamps in some services (e.g., Pinpoint where the target shape uses the trait).

Expected Behavior

Codegen should also handle the case of timestampFormat on target shapes.

Current Behavior

(see above)

Steps to Reproduce

val pinpoint = PinpointClient.fromEnvironment { }

val appId = pinpoint.createApp {
    createApplicationRequest {
        name = "fooApp"
    }
}.applicationResponse?.id

pinpoint.createJourney {
    applicationId = appId
    writeJourneyRequest {
        localTime = true
        schedule {
            startTime = Instant.now()
            timezone = "UTC+07"
        }
    }
}

The above code throws the following exception:

Exception in thread "main" aws.smithy.kotlin.runtime.time.ParseException: parse `2022-10-10T16:42:15.344Z`: error at 4: expected `.` found `-`
	at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt$char$1.invoke(ParserCombinators.kt:85)
	at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt$char$1.invoke(ParserCombinators.kt:82)
	at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt$preceded$1.invoke(ParserCombinators.kt:293)
	at aws.smithy.kotlin.runtime.time.ParserCombinatorsKt$preceded$1.invoke(ParserCombinators.kt:292)
	at aws.smithy.kotlin.runtime.time.ParsersKt.parseEpoch(Parsers.kt:204)
	at aws.smithy.kotlin.runtime.time.Instant$Companion.fromEpochSeconds(InstantJVM.kt:122)
	at aws.sdk.kotlin.services.pinpoint.transform.JourneyScheduleDocumentDeserializerKt.deserializeJourneyScheduleDocument(JourneyScheduleDocumentDeserializer.kt:37)
	at aws.sdk.kotlin.services.pinpoint.transform.JourneyResponseDocumentDeserializerKt.deserializeJourneyResponseDocument(JourneyResponseDocumentDeserializer.kt:96)
	at aws.sdk.kotlin.services.pinpoint.transform.JourneyResponsePayloadDeserializerKt.deserializeJourneyResponsePayload(JourneyResponsePayloadDeserializer.kt:10)
	at aws.sdk.kotlin.services.pinpoint.transform.CreateJourneyOperationDeserializer.deserialize(CreateJourneyOperationDeserializer.kt:28)
	at aws.smithy.kotlin.runtime.http.operation.SdkOperationExecutionKt$decorate$3.invoke(SdkOperationExecution.kt:92)
	at aws.smithy.kotlin.runtime.http.operation.SdkOperationExecutionKt$decorate$3.invoke(SdkOperationExecution.kt:92)
	at aws.smithy.kotlin.runtime.http.operation.DeserializeHandler.call(SdkOperationExecution.kt:148)
	at aws.smithy.kotlin.runtime.http.operation.DeserializeHandler$call$1.invokeSuspend(SdkOperationExecution.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:233)
	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:284)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at foo.ScratchKt.main(Scratch.kt:9)
	at foo.ScratchKt.main(Scratch.kt)

Note that the exception message is expecting a number only, not a fully-formatted date/time.

Possible Solution

Fix the bug.

Context

Discovered while attempting to reproduce aws-sdk-kotlin#723.

Your Environment

  • Smithy Kotlin version used: 0.12.8
  • Platform (JVM/JS/Native): JVM, OpenJDK Runtime Environment Corretto-17.0.4.9.1 (build 17.0.4.1+9-LTS)
  • Operating System and version: Amazon Linux 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant