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.

Action cache filter code incorrectly renders nil response body if response is non-cacheable

#6480

Best explained with an example - consider the simple controller below:

class ActionCachingTestController < ActionController::Base
  caches_action :four_oh_four

  def four_oh_four
    render :text => "404'd!", :status => 404
  end
end

The four_oh_four action returns a HTTP 404 response, which is non-cacheable. The Action cache filter, however, has faulty code that causes the response to be nil (basically an empty page is returned).

I've attached a patch that fixes this by continuing to render the response body in cases where an action is non-cacheable.

Tested against Rails master @ f3e9cbc69.

Reported by Cheah Chu Yeow · February 27th, 2011 @ 03:11 PM

State: committed
Milestone: none
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. Chris Mear
  2. Tekin
    Tekin

    +1 got bit by this today.

    February 28th, 2011 @ 02:51 PM

  3. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • State changed from new to verified
    • Assigned user set to Santiago Pastorino
    • Importance changed from to Low

    Verified. Patch applies to master cleanly and tests pass. Test is good and fails without the fix. :)

    We might want to push this one to stable too. Santiago, what do you think? :)

    February 28th, 2011 @ 04:21 PM

  4. Josh Kalderimis
    Josh Kalderimis
    • Tag changed from actionpack, caches_action, caching, patch to actionpack, patch

    +1 for master and stable, seems like a good correction to both!

    February 28th, 2011 @ 04:48 PM

  5. Lenary
    Lenary

    +1 applies cleanly to 3-0-stable and to master cleanly on my machine, and doesn't even break anything!

    February 28th, 2011 @ 10:47 PM

  6. Kamal Fariz
  7. Wayne See
  8. Repository
    Repository
    • State changed from verified to committed

    (from [2ee55557440a644453482a678e4ff08a4b5ebd3e]) Fix Action caching bug where an action that has a non-cacheable response always renders a nil response body. It now correctly renders the response body.

    Note that only GET and HTTP 200 responses can be cached.

    [#6480 Action cache filter code incorrectly renders nil response body if response is... state:committed]

    Signed-off-by: Santiago Pastorino santiago@wyeworks.com
    https://github.com/rails/rails/commit/2ee55557440a644453482a678e4ff...

    March 2nd, 2011 @ 03:14 PM

  9. Repository
    Repository

    (from [beec6c8b2abfd3286bd7c0a1c7ecb04686af6448]) Fix Action caching bug where an action that has a non-cacheable response always renders a nil response body. It now correctly renders the response body.

    Note that only GET and HTTP 200 responses can be cached.

    [#6480 Action cache filter code incorrectly renders nil response body if response is... state:committed]

    Signed-off-by: Santiago Pastorino santiago@wyeworks.com
    https://github.com/rails/rails/commit/beec6c8b2abfd3286bd7c0a1c7ecb...

    March 2nd, 2011 @ 03:17 PM