Magento Adminhtml Session – Fix addError/addSuccess Rendering Issues

adminhtml

I'm running Magento 1.7.0.2 and have noticed strange behavior with the adminhtml/session messaging system:

Mage::getSingleton('adminhtml/session')->addSuccess("Message"); //or addError();

If you have two pages open in the backend and page 1 calls this function, upon refreshing page 2 (granted that this is done prior to page 1 completing it's refresh), the message will be rendered on page 2.

How to reproduce:

  1. Refresh all caches (SystemCache ManagementSelect AllRefresh
  2. Immediately open Magento's order page (SalesOrders)

You'll now notice that the Orders page has the success message rendered, something along the lines of:

9 cache type(s) refreshed.

See the image below where this message is rendered on the Orders page

enter image description here

Has anybody else experienced this behavior? I'm trying to establish whether this is brought about by my specific instance of Magento as a result of third party extensions or whether it exists in Magento's core.

If the latter, does anybody perhaps know of a fix for this? I know it may not seem very high priority, but there are instances where this behavior could be detrimental to site functionality.

Best Answer

This is somehow a feature. Here is how addError, addSuccess, addNotice, addWarning work.
The message you give as a parameter for those methods are added to the session.
when a page is viewed, Magento checks in the session for any messages.
If there are any, they are displayed and removed from the session.

So when you do an action (like refreshing cache types for example) and the action is finished, but the redirect is not complete, it means you will have the messages in the session already and refreshing any other page will display them and remove them from session.

I don't think there is a way to "fix" this. This also happens on frontend if you move fast enough.

Related Topic