amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

There is no decoder registered for the model named MutationEvent

Open osehmathias opened this issue 2 years ago • 14 comments

Description

When saving an item with datastore, as well as on startup, I get this error about a decoded not being found.

Unhandled DataStoreHubEvent: DataStore.syncStarted 
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Successfully saved model: FlutterSerializedModel(values: ["editing": Amplify.JSONValue.boolean(true), "userInputs": Amplify.JSONValue.object(["associatedField": Amplify.JSONValue.string("record"), "associatedId": Amplify.JSONValue.string("bd358f77-7d4b-4bb6-b4aa-600dd23ea787"), "elements": Amplify.JSONValue.array([])]), "sectionID": Amplify.JSONValue.string("c959d374-1e56-49f7-9bae-888fda62d076"), "enteredAt": Amplify.JSONValue.string("2023-12-20T00:23:13.166000000Z"), "id": Amplify.JSONValue.string("bd358f77-7d4b-4bb6-b4aa-600dd23ea787"), "owner": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3::a5ca2f8e-747c-4919-ae91-951fc1c85cf3"), "createdAt": Amplify.JSONValue.string("2023-12-20T00:23:13.413000000Z"), "updatedAt": Amplify.JSONValue.string("2023-12-20T00:23:13.413000000Z"), "clientID": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3"), "createdBy": Amplify.JSONValue.string("7b56400c-b895-448a-bda3-e86fb829bd0e"), "draft": Amplify.JSONValue.boolean(false), "entryID": Amplify.JSONValue.string("0045183d-f3ff-44a7-ae35-22f624ce74d4"), "__typename": Amplify.JSONValue.string("Record"), "updatedBy": Amplify.JSONValue.null], _modelName: "Record")
Failed to parse the event DataStoreError: No decoder found for model named MutationEvent
Recovery suggestion: There is no decoder registered for the model named MutationEvent. Register models with `ModelRegistry.register(modelName:)` at startup.
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder

Categories

  • [ ] Analytics
  • [ ] API (REST)
  • [ ] API (GraphQL)
  • [ ] Auth
  • [ ] Authenticator
  • [X] DataStore
  • [ ] Notifications (Push)
  • [ ] Storage

Steps to Reproduce

  1. Set up an app using Flutter, Datastore, and Cognito
  2. Create a record in Datastore
  3. Observe the console log in Xcode

Screenshots

No response

Platforms

  • [X] iOS
  • [ ] Android
  • [ ] Web
  • [ ] macOS
  • [ ] Windows
  • [ ] Linux

Flutter Version

3.16.5

Amplify Flutter Version

1.6.0

Deployment Method

Amplify CLI

Schema

type Record
  @model
  @auth(
    rules: [
      { allow: private, provider: iam }
    ]
  ) {
  id: ID!
  enteredAt: AWSDateTime! @index
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime!
  updatedBy: ID
  owner: String
  draft: Boolean
  createdBy: ID @index
  editing: Boolean
  sectionID: ID
    @index(
      name: "recordsBySectionID"
      queryField: "recordsBySectionID"
      sortKeyFields: ["enteredAt"]
    )
  entryID: ID
    @index(
      name: "recordsByEntryID"
      queryField: "recordsByEntryID"
      sortKeyFields: ["enteredAt"]
    )
  entry: Entry @hasOne(fields: ["entryID"])
  clientID: ID
    @index(
      name: "recordsByDate"
      queryField: "recordsByDate"
      sortKeyFields: ["enteredAt"]
    )
  userInputs: [UserInput] @hasMany
}

osehmathias avatar Dec 27 '23 04:12 osehmathias

At first I thought this was related to updating records where there is a belongsTo / hasMany relationship.

However, this is occurring on all updates of data in DataStore

Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Successfully saved model: FlutterSerializedModel(values: ["enteredAt": Amplify.JSONValue.string("2023-12-19T10:49:21.711000000Z"), "updatedBy": Amplify.JSONValue.string("7b56400c-b895-448a-bda3-e86fb829bd0e"), "__typename": Amplify.JSONValue.string("Record"), "editing": Amplify.JSONValue.boolean(true), "createdBy": Amplify.JSONValue.string("7b56400c-b895-448a-bda3-e86fb829bd0e"), "updatedAt": Amplify.JSONValue.string("2023-12-19T10:49:21.743000000Z"), "userInputs": Amplify.JSONValue.object(["associatedField": Amplify.JSONValue.string("record"), "elements": Amplify.JSONValue.array([]), "associatedId": Amplify.JSONValue.string("5cdf707f-6025-4cf2-81c6-b230387bbd6f")]), "id": Amplify.JSONValue.string("5cdf707f-6025-4cf2-81c6-b230387bbd6f"), "clientID": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3"), "draft": Amplify.JSONValue.boolean(false), "createdAt": Amplify.JSONValue.string("2023-12-19T10:49:21.743000000Z"), "owner": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3::a5ca2f8e-747c-4919-ae91-951fc1c85cf3"), "entryID": Amplify.JSONValue.string("f2f78cca-c7d9-407d-8df8-885c1f411761"), "sectionID": Amplify.JSONValue.string("c959d374-1e56-49f7-9bae-888fda62d076")], _modelName: "Record")
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Successfully saved model: FlutterSerializedModel(values: ["createdBy": Amplify.JSONValue.null, "createdAt": Amplify.JSONValue.string("2023-12-19T06:39:38.075000000Z"), "logic": Amplify.JSONValue.null, "addLogic": Amplify.JSONValue.null, "owner": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3"), "order": Amplify.JSONValue.number(10.0), "icon": Amplify.JSONValue.string("LocalDining"), "id": Amplify.JSONValue.string("f2f78cca-c7d9-407d-8df8-885c1f411761"), "updatedAt": Amplify.JSONValue.string("2023-12-23T11:20:31.322000000Z"), "analytics": Amplify.JSONValue.null, "name": Amplify.JSONValue.string("Dinner"), "count": Amplify.JSONValue.number(1.0), "draftRecordID": Amplify.JSONValue.string(""), "entrySections": Amplify.JSONValue.object(["associatedId": Amplify.JSONValue.string("f2f78cca-c7d9-407d-8df8-885c1f411761"), "associatedField": Amplify.JSONValue.string("entryEntrySectionsId"), "elements": Amplify.JSONValue.array([])]), "settings": Amplify.JSONValue.null, "section": Amplify.JSONValue.object(["updatedAt": Amplify.JSONValue.string("2023-12-19T06:39:38.075Z"), "createdBy": Amplify.JSONValue.null, "settings": Amplify.JSONValue.string("{\"hasChart\":true}"), "order": Amplify.JSONValue.number(10.0), "complete": Amplify.JSONValue.null, "createdAt": Amplify.JSONValue.string("2023-12-19T06:39:38.075Z"), "name": Amplify.JSONValue.string("Daily Measurements"), "owner": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3"), "entries": Amplify.JSONValue.object(["associatedId": Amplify.JSONValue.string("c959d374-1e56-49f7-9bae-888fda62d076"), "associatedField": Amplify.JSONValue.string("section"), "elements": Amplify.JSONValue.array([])]), "id": Amplify.JSONValue.string("c959d374-1e56-49f7-9bae-888fda62d076"), "clientID": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3")]), "complete": Amplify.JSONValue.null, "type": Amplify.JSONValue.null, "__typename": Amplify.JSONValue.string("Entry"), "clientID": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3")], _modelName: "Entry")
Failed to parse the event DataStoreError: No decoder found for model named MutationEvent
Recovery suggestion: There is no decoder registered for the model named MutationEvent. Register models with `ModelRegistry.register(modelName:)` at startup.
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Failed to parse the event DataStoreError: No decoder found for model named MutationEvent
Recovery suggestion: There is no decoder registered for the model named MutationEvent. Register models with `ModelRegistry.register(modelName:)` at startup.

osehmathias avatar Dec 27 '23 04:12 osehmathias

Thanks @osehmathias. Is this causing exceptions at the Dart layer or silent exceptions in iOS logs?

haverchuck avatar Dec 27 '23 14:12 haverchuck

@osehmathias does creating a new model without the @auth rule in your schema fix this issue?

Could you share the schema of the simplest model your are using that triggers this error? For example, does a simple model trigger this exception as well?

type SimpleModel @model {
  id: ID!
  indexId: ID! @index(name: "byIndexId")
  content: String!
}

fjnoyp avatar Dec 27 '23 14:12 fjnoyp

@haverchuck - Thanks for the reply. They are silent exceptions in the iOS logs in Xcode. It occurs on every 'save' operation. I have tried to log out / log in, clear the datastore and sync again.

osehmathias avatar Dec 27 '23 23:12 osehmathias

@fjnoyp - I created a simple model very similar to your example:

type SimpleModel
  @model {
  id: ID!
  clientID: ID @index(name: "byClientID")
  content: String
}

It does indeed continue to occur.

This is the save for reference:

 SimpleModel model = SimpleModel(clientID: clientId, content: 'Test');

await Amplify.DataStore.save(model);

This is the error:

Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Successfully saved model: FlutterSerializedModel(values: ["createdAt": Amplify.JSONValue.null, "__typename": Amplify.JSONValue.string("SimpleModel"), "updatedAt": Amplify.JSONValue.null, "content": Amplify.JSONValue.string("Test"), "clientID": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3"), "id": Amplify.JSONValue.string("fce15101-948f-475f-8f12-23ade79c1f9d")], _modelName: "SimpleModel")
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Failed to parse the event DataStoreError: No decoder found for model named MutationEvent
Recovery suggestion: There is no decoder registered for the model named MutationEvent. Register models with `ModelRegistry.register(modelName:)` at startup.

osehmathias avatar Dec 27 '23 23:12 osehmathias

Hi @osehmathias thanks for sharing. It appears there's an issue with your createdAt and updatedAt fields being null and causing an issue with JSON serialization. Those fields should be set automatically but for some reason are not set in your case.

Are you on the latest version of Amplify Flutter (1.6.2) and Amplify CLI? Can you try doing a pub clean/get and also regenerating and pushing your models again via Amplify CLI?

fjnoyp avatar Dec 28 '23 16:12 fjnoyp

Thanks @fjnoyp

To test this, I defined the createdAt and updatedAt fields in the schema so they would be available to set as part of the query.

type SimpleModel @model {
  id: ID
  clientID: ID @index
  content: String
  createdAt: AWSDateTime
  updatedAt: AWSDateTime
}

I ran flutter clean, although the latest version of Amplify Flutter is (1.6.1) as reported by pub.

I ran flutter pub get, followed by amplify codegen models

The error persists.

Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Encoder Foundation.(unknown context at $196c8ec20).__JSONEncoder
Successfully saved model: FlutterSerializedModel(values: ["id": Amplify.JSONValue.string("711bd285-cf04-4e0e-ae9d-5284ef82f4f3"), "__typename": Amplify.JSONValue.string("SimpleModel"), "createdAt": Amplify.JSONValue.string("2023-12-28T22:20:55.372693000Z"), "clientID": Amplify.JSONValue.string("a5ca2f8e-747c-4919-ae91-951fc1c85cf3"), "updatedAt": Amplify.JSONValue.string("2023-12-28T22:20:55.372781000Z"), "content": Amplify.JSONValue.string("This")], _modelName: "SimpleModel")
Failed to parse the event DataStoreError: No decoder found for model named MutationEvent
Recovery suggestion: There is no decoder registered for the model named MutationEvent. Register models with `ModelRegistry.register(modelName:)` at startup.

I should add that data appears to be getting saved, and this error, which only appears in Xcode, doesn't appear to interfere with running the app. However, as I am sure you can relate, it is pleasing to have no errors in the console.

osehmathias avatar Dec 28 '23 22:12 osehmathias

Hey @osehmathias can you please remove those fields? They are created and populated automatically within Amplify so creating them again can break the serialization step.

fjnoyp avatar Dec 28 '23 22:12 fjnoyp

I will get back to you in a few days when I have tested further on fresh testing apps.

osehmathias avatar Dec 29 '23 22:12 osehmathias

Hello @osehmathias - I believe these logs can be ignored. I do agree that the logs should be removed though. I will mark this as a bug. If you believe that there are issues impacting your application related to these logs, please let us know.

Jordan-Nelson avatar Jan 08 '24 17:01 Jordan-Nelson

@Jordan-Nelson - thanks for following up. The bug is not impeding development or use of the product, so it has taken me a while to come back to it.

I was not able to reproduce this error on a minimal new build e.g. from the AWS Tutorial for Flutter. However, when I create a flutter app and integrate one of my existing backends, I still get it.

The flutter app I reported from originally uses an existing backend that is complex in its nature - enums, custom types, multiple auth rules, and so forth. It is not obvious where the problem originates.

I will post back in the thread if I find something or if this starts blocking function.

osehmathias avatar Jan 10 '24 02:01 osehmathias

@osehmathias Apologies for the delay. Thank you for that info.

Jordan-Nelson avatar May 01 '24 17:05 Jordan-Nelson

Did anyone has find any solution for this problem? I am using OIDC auth strategy and facing this same issue.

akrutipanchal avatar Aug 15 '24 19:08 akrutipanchal

@workoholicgeek sorry that you are facing this issue. Do you work with @osehmathias on the same project? if not would you please open a new issue and fill out the issue template so that we will have the information to investigate it further. Thanks.

NikaHsn avatar Aug 19 '24 21:08 NikaHsn

Same issue here. Different project. Only happens on iOS.

Haapavuo avatar Sep 08 '24 12:09 Haapavuo

@Haapavuo a fix for this was already released. I'm going to close this issue as the original issue was fixed.

Please upgrade to the latest of Amplify DataStore and verify the error is gone.

If you are on the latest and still seeing this issue, please open a new issue so we can gather enough information to reproduce.

Equartey avatar Sep 09 '24 17:09 Equartey

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Sep 09 '24 17:09 github-actions[bot]