Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanks. I also realized that when creating an order, a success message is sent to the session for sales_order view giving you a success message, so 'fixing' it would probably be a bad idea. –  moose Mar 12 at 8:52

I can't imagen where this behaviour is a problem. But beside of this, this behaviour can only be fixed if you use two different sessions. The errors are saved to the session and are shown the next time, the message block is loaded.

You can fix this only on your side, e.g using more than one browser.

share|improve this answer
    
Thanks @Fabian Blechschmidt, it's not a major issue but if (for example) you call a function via AJAX which (for instance) sends an email to a customer. An error could be encountered if the mail server is not responsive and the error would be loaded into the session. However, because this is called by AJAX, the page won't reload and as a result you won't immediately see the error message. But yeah, as I mentioned, not THAT much of an issue. Will upvote as soon as I can, reached the limit today. –  moose Mar 12 at 8:52
    
If you call something via ajax, you should handle this ;-) –  Fabian Blechschmidt Mar 12 at 8:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.