-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model fragments broken against Ember Data 3.28 #406
Comments
Which version of this addon did you use? |
@knownasilya I used |
Any chance you can make a small reproduction app? |
@knownasilya I've already included a zipped reproduction app in my first comment, at the very end is a link: |
🤦♂️ |
I can confirm this. I just bumped my app to 3.28.0 and was bitten by the same error. |
Give #407 a try. "ember-data-model-fragments": "knownasilya/ember-data-model-fragments#e22f3b80285f" And npm/yarn install. |
@knownasilya that fix is not quite enough, unfortunately. If you have a fragment array, that'll fail too under 3.28 (it requires a similar fix in the fragment array serializer). Either way, I don't think the proposed fix in the PR is the right way to go. What strikes me as weird is the fact that what's passed in is no longer a snapshot. Is that expected behavior? What exactly changed in Ember/Ember Data that caused this? I feel like patching the transforms like that may still cause issues elsewhere down the line if we don't know what's happening under the hood. |
@knownasilya @kevinkucharczyk I believe found the culprit: CoreStore in 3.27.1 doesn't have let snapshot = internalModel.createSnapshot(options);
this._pendingSave.push({
snapshot: snapshot,
resolver: resolver,
});
emberBackburner.scheduleOnce('actions', this, this.flushPendingSave); In 3.28.1 let snapshot = new Snapshot(options, identifier, this._store); For some reason, fragments are not correctly converted to snapshots in this case. I don't know if it's bug or desired behavior. I'm not an Ember expert by any means so I'm not sure what's the most appropriate solution but in 3.28.1 serializer.serialize(snapshot) operates on |
@runspired any advice? |
@lowski The underlying issue here is more likely related to the activation of CUSTOM_MODEL_CLASS features, this library still hasn't fully converted to the record-data approach to fragments and likely this leads this code and this code in Snapshot to behave differently. Probably the FragmentRecordData is storying the fragment as the value within the record-data instead of the serialized value. |
@knownasilya I've looked into this again and it looks this addon overrides @runspired what is the best way to modify |
The right way to do this is to store the serialized form in the fragment RecordData, no private apis would be necessary then. |
@runspired could you provide more information how to do it? I'd like to try making this add-on compatible with Ember Data 3.28. From my understanding fragments are basically computed properties on the model and they use Could you also explain what |
@knownasilya I've just tested it on my project and #407 doesn't fix this issue - now I'm getting a following error:
@kevinkucharczyk can you check latest |
Can you create a failing test as a PR? |
@knownasilya there are already failing tests on existing test suite related to that error: https://github.com/adopted-ember-addons/ember-data-model-fragments/runs/3613005831?check_suite_focus=true#step:7:641 https://github.com/adopted-ember-addons/ember-data-model-fragments/runs/3613005831?check_suite_focus=true#step:7:456 |
I encounter exactly the same issue than @lowski with the latest commit on master ☝️🤔 |
The same issue in our project. |
As @lowski pointed out, the problem may be that before 3.28 the Snapshot for serialization is created by calling I was able to dirty fix it by calling
There is probably a better way / place to do this. |
Here's a quick workaround, import FragmentTransform from 'ember-data-model-fragments/transforms/fragment';
import FragmentArrayTransform from 'ember-data-model-fragments/transforms/fragment-array';
FragmentTransform.reopen({
serialize(snapshot) {
return this._super(snapshot?._createSnapshot?.() ?? snapshot);
},
});
FragmentArrayTransform.reopen({
serialize(snapshots) {
return this._super(snapshots?._createSnapshot?.() ?? snapshots);
},
}); |
I merged that fix, so master should work as well. Will try to research a bit more and see if there is a better solution. |
The above fix is incomplete. Here's what did work in our app. Note I still am advocating for fixing the root cause (as currently we are hacking into internals instead of using record-data as designed), but this will help to unblock ember-data upgrades (there is still a separate issue I will open separately). Fragment: import Transform from "ember-data-model-fragments/transforms/fragment";
export default class Fragment extends Transform {
serialize(snapshot) {
if (!snapshot) {
return null;
}
const { store } = this;
const serializer = store.serializerFor(
snapshot.modelName || snapshot.constructor.modelName
);
return serializer.serialize(
snapshot.modelName ? snapshot : snapshot._internalModel.createSnapshot(),
{ includeId: true }
);
}
} Fragment Array:
|
There's also an issue with property change notifications for I did attempt doing things the "right way" with record-data. I'll open a PR. |
That's the other issue. It's due ember-data removing the state machine. |
Thx @runspired ! The patch worked very well for our 3.28 upgrade. We only had to adapt it a bit to work with polymorphic fragmentArray relationship (essentially instead of using |
Could you try with the latest release @kevinkucharczyk ? |
I was testing Ember Data Model Fragments against the latest Ember Data - version 3.28 - and unfortunately it looks like they're not compatible. Here's what happens when I try to save a model that contains a fragment:
This particular problem seems to happen at
ember-data-model-fragments/addon/transforms/fragment.js
Line 38 in b1a661b
The
serialize
method is expecting aSnapshot
, but actually receives the model instance of the fragment (I'm not sure why) -modelName
is empty there.Here's a minimal reproduction on a fresh Ember app:
ember-quickstart.zip
The text was updated successfully, but these errors were encountered: