aws-amplify / aws-amplify/amplify-studio
Getting "Cannot return null for non-nullable type: 'AWSDateTime' within parent"
- Dominant language
- No language data
- Stars
- 135
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Description
### Description
I am getting the following error in `onUpdate` when subscribed to real-time events on both `onCreate` and `onUpdate`. When an object is created, I am successfully receiving `event.data` in `onCreate` subscription but I am receiving an error in `onUpdate` subscription. Here is the error event in `onUpdate`:
```
I/flutter ( 3828): GraphQLResponse: {
I/flutter ( 3828): "data": null,
I/flutter ( 3828): "errors": [
I/flutter ( 3828): {
I/flutter ( 3828): "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Order' (/onUpdateOrder/createdAt)",
I/flutter ( 3828): "path": [
I/flutter ( 3828): "onUpdateOrder",
I/flutter ( 3828): "createdAt"
I/flutter ( 3828): ]
I/flutter ( 3828): },
I/flutter ( 3828): {
I/flutter ( 3828): "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Order' (/onUpdateOrder/updatedAt)",
I/flutter ( 3828): "path": [
I/flutter ( 3828): "onUpdateOrder",
I/flutter ( 3828): "updatedAt"
I/flutter ( 3828): ]
I/flutter ( 3828): }
I/flutter ( 3828): ]
I/flutter ( 3828): }
```
Code:
```
void subscribeToOrderCreate() {
final subscriptionRequest = ModelSubscriptions.onCreate(Order.classType);
final Stream> operation = Amplify.API.subscribe(
subscriptionRequest,
onEstablished: () => safePrint('Order create subscription established'),
);
subscription = operation.listen(
(event) {
safePrint(event);
},
onError: (Object e) =>
safePrint('Error in order create subscription stream: $e'),
);
}
```
```
void subscribeToOrderUpdate() {
final subscriptionRequest = ModelSubscriptions.onUpdate(Order.classType);
final Stream> operation = Amplify.API.subscribe(
subscriptionRequest,
onEstablished: () => safePrint('Order update subscription established'),
);
subscription = operation.listen(
(event) {
safePrint(event);
},
onError: (Object e) =>
safePrint('Error in order update subscription stream: $e'),
);
}
```
### Categories
- [ ] Analytics
- [ ] API (REST)
- [X] API (GraphQL)
- [ ] Auth
- [ ] Authenticator
- [ ] DataStore
- [ ] Notifications (Push)
- [ ] Storage
### Steps to Reproduce
1. Subscribe to `onCreate` and `onUpdate` on a model.
2. Create an object in that model.
3. `onUpdate` subscription will receive the above error:
### Screenshots
_No response_
### Platforms
- [ ] iOS
- [X] Android
- [ ] Web
- [ ] macOS
- [ ] Windows
- [ ] Linux
### Flutter Version
Flutter 3.22.1
### Amplify Flutter Version
2.4.0
### Deployment Method
Amplify CLI (Gen 1)
### Schema
```GraphQL
enum DubbingType {
ORIGNAL
REPLACED
}
enum OrderStatus {
TRANSCRIBE
TRANSCRIBING
TRANSCRIBE_COMPLETED
TRANSLATE
TRANSLATING
TRANSLATE_COMPLETED
GENERATE_MERGE_AUDIO
GENERATE_MERGE_AUDIO_COMPLETED
PURCHASE
COMPLETED
FAILED
CANCELLED
}
type Order @model @auth(rules: [{ allow: public }]) {
id: ID!
userId: ID
title: String
url: AWSURL
status: OrderStatus
duration: Int
fps: Float
orgLanguageIso: String
newLanguageName: String
newLanguageIso: String
cost: Int
orgVideoKey: String
orgLanguageName: String
orgSrtKey: String
newSrtKey: String
orgTranscriptKey: String
newTranscriptKey: String
orgWaveformKey: String
newWaveformKey: String
newAudioKey: String
paid: Boolean
newVideoKey: String
dubbingType: DubbingType
configKey: String
retryCount: Int
progress: Float
failedReason: String
}
type Subscription {
onOrderById(id: ID!): Order @aws_subscribe(mutations: ["updateOrder"])
}
```
1. Why `onUpdate` subscription is receiving this `event` in the first place when an item is created only?
2. Both the `createdAt` and `updatedAt` are helper fields and not explicitly overwritten. These fields are populated by Amplify.
Contributor guide
Research direction
Start with the GraphQL schema and the generated ModelSubscriptions.onCreate/onUpdate requests, then compare the payload produced when an Order is created. Investigate why the update subscription is triggered and why createdAt and updatedAt are null despite being helper fields; done means identifying the cause and documenting or reproducing a verified correction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter, graphql
- Domain
- api, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100