{"action":"created","issue":{"url":"https://api.github.com/repos/emberjs/data/issues/5025","repository_url":"https://api.github.com/repos/emberjs/data","labels_url":"https://api.github.com/repos/emberjs/data/issues/5025/labels{/name}","comments_url":"https://api.github.com/repos/emberjs/data/issues/5025/comments","events_url":"https://api.github.com/repos/emberjs/data/issues/5025/events","html_url":"https://github.com/emberjs/data/issues/5025","id":237633374,"number":5025,"title":"`FilteredRecordArray` has null values after `unloadRecord` w/ 2.13 and newer.","user":{"login":"workmanw","id":825487,"avatar_url":"https://avatars3.githubusercontent.com/u/825487?v=4","gravatar_id":"","url":"https://api.github.com/users/workmanw","html_url":"https://github.com/workmanw","followers_url":"https://api.github.com/users/workmanw/followers","following_url":"https://api.github.com/users/workmanw/following{/other_user}","gists_url":"https://api.github.com/users/workmanw/gists{/gist_id}","starred_url":"https://api.github.com/users/workmanw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/workmanw/subscriptions","organizations_url":"https://api.github.com/users/workmanw/orgs","repos_url":"https://api.github.com/users/workmanw/repos","events_url":"https://api.github.com/users/workmanw/events{/privacy}","received_events_url":"https://api.github.com/users/workmanw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-06-21T19:02:39Z","updated_at":"2017-07-25T18:00:14Z","closed_at":null,"body":"This is very similar to #4986, however it has a slightly different cause so I wanted to file it as a separate issue. \r\n\r\n### What's happening\r\nI created specific twiddle to demonstrated:\r\n\r\n* [ember-data-2.12.2 (working)](https://ember-twiddle.com/50f002a0e1a36ce249b7b3ccd4062eee?openFiles=controllers.todo-list.js%2C)\r\n* [ember-data-2.13.2 (broken)](https://ember-twiddle.com/fb8383d82a1b92a8be61e618aa8862ab?openFiles=controllers.todo-list.js%2C)\r\n\r\nI would direct your attention to the `removeTodo` action in the `todo-list` controller. What's happening is that when I call `unloadRecord` the filtered array replaces the value of the model that was just unloaded with `null`.\r\n\r\nThis `null` value exists only until the end of the runloop because there is a `_flush` function scheduled to run in the `action` queue to clean these up.\r\n\r\n### Why is this happening?\r\n\r\nWith 2.13 there was a change made (#4593) that set's the internal model's record to `null` when it's reset or dematerialized (this is new functionality and important to understanding the issue). See: [internal-model.js#L360](https://github.com/emberjs/data/blob/ac0192184/addon/-private/system/model/internal-model.js#L360). \r\n\r\nAlso, because the filtered array's content is a list of internal models, it has to look up the record via `objectAtContent` which produces a `null` values for unloaded records. See: [record-array.js#L107-L110](https://github.com/emberjs/data/blob/ac019218465456991119089cf32482f09f3db898/addon/-private/system/record-arrays/record-array.js#L107-L110). So that means when someone tries to use `objectAt` or `toArray` it'll get a list with a null value in place of the item that was just unloaded.\r\n\r\n### What did it do before?\r\n\r\nWith 2.12 the record was not nullified from the internal model. So while the array would produce a stale value (i.e. an unloaded record) until the end of the runloop, it was more desirable than a null value. \r\n\r\n### Why is this a problem?\r\n\r\nIn my case, after the unload action happens and it schedules a `_flush` task in the `actions` queue, however it moves on to other tasks in the `render` queue. That's when views and computed properties access the array, hit the null value that they weren't expecting and throw an exception.\r\n\r\nI could make my application more durable to assume that values in these filtered arrays could be null, but it feels like the right answer is they should never been null. \r\n"},"comment":{"url":"https://api.github.com/repos/emberjs/data/issues/comments/317819212","html_url":"https://github.com/emberjs/data/issues/5025#issuecomment-317819212","issue_url":"https://api.github.com/repos/emberjs/data/issues/5025","id":317819212,"user":{"login":"stefanpenner","id":1377,"avatar_url":"https://avatars2.githubusercontent.com/u/1377?v=4","gravatar_id":"","url":"https://api.github.com/users/stefanpenner","html_url":"https://github.com/stefanpenner","followers_url":"https://api.github.com/users/stefanpenner/followers","following_url":"https://api.github.com/users/stefanpenner/following{/other_user}","gists_url":"https://api.github.com/users/stefanpenner/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanpenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanpenner/subscriptions","organizations_url":"https://api.github.com/users/stefanpenner/orgs","repos_url":"https://api.github.com/users/stefanpenner/repos","events_url":"https://api.github.com/users/stefanpenner/events{/privacy}","received_events_url":"https://api.github.com/users/stefanpenner/received_events","type":"User","site_admin":false},"created_at":"2017-07-25T18:00:14Z","updated_at":"2017-07-25T18:00:14Z","body":"@workmanw if you have cycles, do you mind submitting a failing test?"}}
{"actor":{"display_login":"stefanpenner"}}