Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] ActiveRecord::Base#reload didn't respect default_scope conditions

#3166

Just a quick bug fix for reloading a model which has a default_scope set but doesn't meet the condition:

It lead to a RecordNotFound exception, in case the model didn't met the default_scope condition (anymore) - this was obviously a bug. This quick fix makes use of with_exclusive_scope in the reload method to return the updated model in any case. See test for full example.

Cheers Tobi

Reported by Tobi · September 8th, 2009 @ 03:24 PM

State: committed
Milestone: none
Assigned to: José Valim José Valim
Importance: none

Activity

  1. Tobi
    Tobi

    ehm, and the patch attached ;-)

    September 8th, 2009 @ 03:25 PM

  2. Tobi
    Tobi
    • Tag set to 2.3.4, activerecord, default_scope, patch, reload, with_exclusive_scope

    September 9th, 2009 @ 10:58 AM

  3. Tobi
    Tobi

    there was an issue with protected method. is fixed, see updated patch

    September 11th, 2009 @ 10:17 AM

  4. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.4, activerecord, default_scope, patch, reload, with_exclusive_scope to 2.3.4, activerecord, bugmash, default_scope, patch, reload, with_exclusive_scope

    September 25th, 2009 @ 12:29 PM

  5. John Guenin
    John Guenin

    +1 verified bug & patch.

    Patch applies cleanly to master & 2-3-stable.

    Good catch!

    September 26th, 2009 @ 10:51 PM

  6. rbxbx
    rbxbx

    +1 patch applies cleanly to master and stable, tests passing.

    :)

    September 26th, 2009 @ 11:00 PM

  7. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2.3.4, activerecord, bugmash, default_scope, patch, reload, with_exclusive_scope to 2.3.4, activerecord, bugmash-review, default_scope, patch, reload, with_exclusive_scope

    September 27th, 2009 @ 12:00 PM

  8. José Valim
    José Valim
    • Assigned user set to José Valim

    February 19th, 2010 @ 05:03 PM

  9. Repository
    Repository

    (from [b06e5dce9786bf69ac5f114286fc9236dc9bfe5c]) fixed a 'RecordNotFound' bug when calling 'reload' on a object which doesn't met the default_scope conditions, added test [#3166 [PATCH] ActiveRecord::Base#reload didn't respect default_scope conditions status:resolved]

    The reload method didn't made use of 'with_exclusive_scope' when reloading the object. This lead to a RecordNotFound exception, in case the object doesn't met the default_scope condition (anymore) - which is obviously a bug. This quick fix makes use of with_exclusive_scope in the reload method as well. See test for full example.

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/b06e5dce9786bf69ac5f114286fc92...

    February 26th, 2010 @ 10:40 AM

  10. José Valim
    José Valim
    • State changed from new to committed

    Applied.

    February 26th, 2010 @ 10:41 AM

  11. Repository
    Repository

    (from [4db72b702f7faca7da30a64e45daeee13733762a]) fixed a 'RecordNotFound' bug when calling 'reload' on a object which doesn't met the default_scope conditions, added test [#3166 [PATCH] ActiveRecord::Base#reload didn't respect default_scope conditions status:resolved]

    The reload method didn't made use of 'with_exclusive_scope' when reloading the object. This lead to a RecordNotFound exception, in case the object doesn't met the default_scope condition (anymore) - which is obviously a bug. This quick fix makes use of with_exclusive_scope in the reload method as well. See test for full example.

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/4db72b702f7faca7da30a64e45daee...

    February 26th, 2010 @ 11:15 AM

  12. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2.3.4, activerecord, bugmash-review, default_scope, patch, reload, with_exclusive_scope to 2.3.4, activerecord, default_scope, patch, reload, with_exclusive_scope

    May 15th, 2010 @ 06:37 PM