adopted-ember-addons / ember-data-model-fragments

Ember Data addon to support nested JSON documents
MIT License
370 stars 114 forks source link

Error while validating with ember-model-validator #478

Open jayseo5953 opened 1 year ago

jayseo5953 commented 1 year ago

Hello, I have a model with a fragment from ember-data-model-fragments And I use ember-model-validator Before saving I run validate to validate fields.

When I have an error in a field (ex, name) , it throws this uncaught error on the adapter instead of adding the field error (ex "Name is empty") to the model with the fragment even though the error that the validation caught was not the fragment property.

Error: Attempted to handle eventbecameErroron <fragments/my-fragment:null> while in state root.loaded.saved.

the stack trace is this

commitWasRejected

commitWasRejected

_fragmentCommitWasRejected

In the first commitWasRejected, updating it from

  const fragment =
        key in this._inFlightFragments
          ? this._inFlightFragments[key]
          : this._fragmentData[key];
      if (fragment == null) {
        continue;
      }
      behavior.commitWasRejected(fragment)

to

  const fragment = this._inFlightFragments[key]
      if (fragment == null) {
        continue;
      }
      behavior.commitWasRejected(fragment)

to remove the tenary operator to strictly use this._inFlightFragments[key] seems to solve the issue but I am not sure if this is safe to do. All I was doing was to revert to this 5.0 version

versions

"ember": 4,4,1,
"ember-data": "~4.4.0",
"ember-model-validator": "3.14.0",
"ember-data-model-fragments": "^6.0.3",