aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.31k stars 242 forks source link

There is no decoder registered for the model named MutationEvent #4287

Closed osehmathias closed 5 days ago

osehmathias commented 8 months ago

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

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

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 commented 8 months ago

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.
haverchuck commented 8 months ago

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

fjnoyp commented 8 months ago

@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!
}
osehmathias commented 8 months ago

@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 commented 8 months ago

@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.
fjnoyp commented 8 months ago

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?

osehmathias commented 8 months ago

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.

fjnoyp commented 8 months ago

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.

osehmathias commented 8 months ago

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

Jordan-Nelson commented 8 months ago

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.

osehmathias commented 8 months ago

@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.

Jordan-Nelson commented 4 months ago

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

workoholicgeek commented 1 month ago

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

NikaHsn commented 3 weeks ago

@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.

Haapavuo commented 6 days ago

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

Equartey commented 5 days ago

@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.

github-actions[bot] commented 5 days ago

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.