{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/13184","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/13184/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/13184/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/13184/events","html_url":"https://github.com/laravel/framework/pull/13184","id":148860568,"number":13184,"title":"[5.2] Make sure unguarded() does not change unguarded state on exception","user":{"login":"JeroenNoten","id":4370753,"avatar_url":"https://avatars.githubusercontent.com/u/4370753?v=3","gravatar_id":"","url":"https://api.github.com/users/JeroenNoten","html_url":"https://github.com/JeroenNoten","followers_url":"https://api.github.com/users/JeroenNoten/followers","following_url":"https://api.github.com/users/JeroenNoten/following{/other_user}","gists_url":"https://api.github.com/users/JeroenNoten/gists{/gist_id}","starred_url":"https://api.github.com/users/JeroenNoten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JeroenNoten/subscriptions","organizations_url":"https://api.github.com/users/JeroenNoten/orgs","repos_url":"https://api.github.com/users/JeroenNoten/repos","events_url":"https://api.github.com/users/JeroenNoten/events{/privacy}","received_events_url":"https://api.github.com/users/JeroenNoten/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-16T15:02:34Z","updated_at":"2016-04-16T15:23:34Z","closed_at":"2016-04-16T15:23:28Z","pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/13184","html_url":"https://github.com/laravel/framework/pull/13184","diff_url":"https://github.com/laravel/framework/pull/13184.diff","patch_url":"https://github.com/laravel/framework/pull/13184.patch"},"body":"This makes sure that when an exception is thrown in the callback passed to `Model::unguarded()`, the Model is still guarded afterwards. It uses the `try .. finally` construct. I also added a unit test.\r\n\r\nA use case when this can happen is in `FactoryBuilder::makeInstance`, which throws an exception when it cannot find the model factory. In tests, this can result in strange errors in other tests, because all models are unguarded afterwards (also in other test cases) when this exception is thrown. So then tests will fail when they shouldn't. This PR prevents this kind of situations."},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/210839255","html_url":"https://github.com/laravel/framework/pull/13184#issuecomment-210839255","issue_url":"https://api.github.com/repos/laravel/framework/issues/13184","id":210839255,"user":{"login":"GrahamCampbell","id":2829600,"avatar_url":"https://avatars.githubusercontent.com/u/2829600?v=3","gravatar_id":"","url":"https://api.github.com/users/GrahamCampbell","html_url":"https://github.com/GrahamCampbell","followers_url":"https://api.github.com/users/GrahamCampbell/followers","following_url":"https://api.github.com/users/GrahamCampbell/following{/other_user}","gists_url":"https://api.github.com/users/GrahamCampbell/gists{/gist_id}","starred_url":"https://api.github.com/users/GrahamCampbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GrahamCampbell/subscriptions","organizations_url":"https://api.github.com/users/GrahamCampbell/orgs","repos_url":"https://api.github.com/users/GrahamCampbell/repos","events_url":"https://api.github.com/users/GrahamCampbell/events{/privacy}","received_events_url":"https://api.github.com/users/GrahamCampbell/received_events","type":"User","site_admin":false},"created_at":"2016-04-16T15:23:34Z","updated_at":"2016-04-16T15:23:34Z","body":"Please send this bug fix to 5.1."}}