Skip to content

fix(api): Serialize TemporalDateTime in identifier for ModelQueries.get - #7255

Draft
VarshithaPamisetty wants to merge 7 commits into
mainfrom
fix/api-temporal-datetime-identifier
Draft

fix(api): Serialize TemporalDateTime in identifier for ModelQueries.get#7255
VarshithaPamisetty wants to merge 7 commits into
mainfrom
fix/api-temporal-datetime-identifier

Conversation

@VarshithaPamisetty

@VarshithaPamisetty VarshithaPamisetty commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

ModelQueries.get() on a model whose custom identifier includes a TemporalDateTime threw JsonUnsupportedObjectError. The get-by-identifier path passed identifier values straight to JSON encoding without running them through _getSerializedValue (which the list/filter path already uses), so the TemporalDateTime was never stringified.

This serializes identifier values for both the get variables and the composite-key document. Adds a Gen2-generated CpkTemporalPrimaryKey test model + regression test.

Testing

  • New regression test in graphql_test.dart (asserts the get document and JSON-encodable, correctly-serialized variables).
  • Verified end-to-end against a live AppSync API: create + ModelQueries.get() by the composite key with a TemporalDateTime, across multiple date formats (incl. timezone offset), all returning cleanly.

Supersedes #7237.

Fixes #6298

Run get-by-identifier values through _getSerializedValue (like list/filter) so a TemporalDateTime custom primary key no longer throws JsonUnsupportedObjectError.

Issues:
#6298
@codecov-commenter

codecov-commenter commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 40.98%. Comparing base (b0c2048) to head (1e2bc2e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7255      +/-   ##
==========================================
+ Coverage   40.97%   40.98%   +0.01%     
==========================================
  Files         121      121              
  Lines        8273     8273              
  Branches     3598     3598              
==========================================
+ Hits         3390     3391       +1     
+ Misses       4883     4882       -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +25 to +26
final variables = GraphQLRequestFactory.instance
.buildVariablesForGetRequest(modelIdentifier: modelIdentifier);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this need to be added to delete operations too.

@cadivus cadivus Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And do we need to adapt test models (e.g. test/test_models/schema.graphql)? Do we need to add something like

type CpkTemporalPrimaryKey @model {
  hwid: String! @primaryKey(sortKeyFields: ["sessionStart"])
  sessionStart: AWSDateTime!
}

@VarshithaPamisetty VarshithaPamisetty Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the delete operation and the CpkTemporalPrimaryKey type to the test schema (as suggested).


// NOTE: This file is generated and may not follow lint rules defined in your app
// Generated files can be excluded from analysis in analysis_options.yaml
// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Who/what generated it? The Amazon header is usually not used for autogenerated files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the header manually to match our license convention, it's not from modelgen. Yes, it doesn't belong on a generated file. I'll remove it and restore the generator's default.

Comment on lines +109 to +116
CpkTemporalPrimaryKey: a
.model({
hwid: a.string().required(),
sessionStart: a.datetime().required(),
})
.identifier(["hwid", "sessionStart"])
.authorization((allow) => [allow.authenticated()]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where is this used in the modified tests? If we want to extend e2e, we should also modify the test itself (example/integration_test/graphql/user_pools_test.dart).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added an e2e test that exercises it, along with the generated example model it needs.

Applies the get-path serialization to delete via a shared serializeModelIdentifier helper so ModelMutations.delete() with a TemporalDateTime custom key no longer throws JsonUnsupportedObjectError. Restores the generator's default header on the CpkTemporalPrimaryKey fixture, adds the type to test_models/schema.graphql, and adds an e2e test (create/get/delete by the composite key) plus the matching example model. Addresses review feedback on #7255.

Issues:
#6298
@VarshithaPamisetty
VarshithaPamisetty marked this pull request as draft August 12, 2026 10:33
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.

Get Query Using TemporalDateTime Objects

3 participants