mobx-state-tree
mobx-state-tree copied to clipboard
My model returns fields as null, if I created model fields with types.maybeNull and use model in types.union
Bug report
- [x] I've checked documentation and searched for existing issues
- [x] I've made sure my project is based on the latest MST version
- [x] Fork this code sandbox or another minimal reproduction.
Sandbox link or minimal reproduction code https://codesandbox.io/s/sad-dan-0nhji
Describe the expected behavior I have a model with types.maybeNull field. Then I use it model in another model with types.union and types.late (circular dependencies). I create store with snapshot and expect store will contains all data, but it ignores some snapshot data and show fields as null. I also asked this question in spectrum.chat https://spectrum.chat/mobx-state-tree/general/i-dont-understand-behavior-of-types-maybenull-with-types-late~99969a6d-b59f-40be-98c9-8db9ab1a152d
Model created with snapshot:
const group = Group.create({
name: "New group",
priority: 1,
filter: {
filters: [
{
filters: [
{ field: "chat_channel", value: "some channel", operator: "=" },
{ field: "eq_utm_term", value: "11121", operator: "=" }
],
condition: "and"
},
{
filters: [
{ field: "tags", value: "some tag 1", operator: "=" },
{ field: "tags", value: "some tag 2", operator: "=" },
{ field: "tags", value: "some tag 3", operator: "=" }
],
condition: "or"
}
],
condition: "or"
}
});
I expected group instance will equal to my snapshot. If in SingleFilter model remove types.maybeNull it will work as expected.
Describe the observed behavior Group instance is equal to:
{
name: "New group",
priority: 1,
filter: {
field: null,
operator: null,
value: null,
},
}
I'd say we need to write a failing test for this behaviour then try to figure out what exactly is causing it.
Hey folks - looks like @willrax came up with a PR to close this issue out. Hopefully we can clean up CI for that PR and close this issue.
For now, I'm going to drop a label here that it has a PR that would fix the problem.
I misunderstood that PR - it was just adding a failing test. I'm going to leave the label, but we still are open to an actual fix.
Here's the failing test PR, I'm closing it out today for cleanup, but it's a great place to start: https://github.com/mobxjs/mobx-state-tree/pull/1652