Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 3
[Solved] Varien Lib Error
 
Mageho
Sr. Member
 
Avatar
Total Posts:  291
Joined:  2008-03-24
France, Paris
 

Good morning,

I think I find an error in varien lib.

When you load several products in one page like two product list or when you call many products through module (new, specials, etc.) and two products are identical, magento generate an error like this :

Item (Mage_Catalog_Model_Product) with the same id “‘11726” already exist

I don’t understand why magento create an exception for this.

If you meet this problem in your environment, modify this method :
lib/Varien/Data/Collection.php (Starting line 314)

public function addItem(Varien_Object $item)
    
{
        $itemId 
$this->_getItemId($item);
        if (!
is_null($itemId)) {
            
if (isset($this->_items[$itemId])) {
              
//  throw new Exception('Item ('.get_class($item).') with the same id "'.$item->getId().'" already exist');
            
else {
                $this
->_items[$itemId] $item;
            
}
        }
        
else {
            $this
->_items[] $item;
        
}
        
return $this;
    
}

In other way, I want to talk about image management.
Maybe Moshe can answer to my question :
Why magento team doesn’t include my solution to handle image proportion :
Image Resize Function Scale
Because in default installation and in other update of magento, we have the default image management.

Cheers,
Ilan

 
Magento Community Magento Community
Magento Community
Magento Community
 
RPGShop
Sr. Member
 
Total Posts:  143
Joined:  2008-06-16
 

I’m using 1.1.2 yet as I’m waiting for all the 1.1.5 bug fixes before I go through another nightmare upgrade.

But I tried to add some more store fronts to my data (and it copies a lot of data to do so). I had 2 store fronts and added a 3rd. Now my system is generating the same error as listed above when you select SOME products. Like 3 out of 20 on my front page. I donno why and it’s a very stupid fix, but the above fix did work and the site seems to be functioning fine again.

Should this be reported as a bug?
James

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mageho
Sr. Member
 
Avatar
Total Posts:  291
Joined:  2008-03-24
France, Paris
 

it’s a very stupid fix

Thanks.

But I would rather say badly conceived.

It been a while since I report this error, and it always present in current release.

 
Magento Community Magento Community
Magento Community
Magento Community
 
RPGShop
Sr. Member
 
Total Posts:  143
Joined:  2008-06-16
 

Hee.. yeah, didn’t mean any insult to you. I mean the fact that we HAD to fix it is stupid.

James

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageParts
Guru
 
Avatar
Total Posts:  415
Joined:  2007-11-18
 

Good job on the fix! smile

I received that same error when I was simply trying to view the problem reports of my newsletter. All works now, cheers mate wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michael_1
Enthusiast
 
Total Posts:  826
Joined:  2007-08-31
 

If there are duplicate elements in the data that you are filling your collection with, that means that you getting that data in a wrong way. So the solution you posted is not a real solution, it just hides the original bug.

 
Magento Community Magento Community
Magento Community
Magento Community
 
RPGShop
Sr. Member
 
Total Posts:  143
Joined:  2008-06-16
 
Michael - 02 October 2008 04:06 AM

If there are duplicate elements in the data that you are filling your collection with, that means that you getting that data in a wrong way. So the solution you posted is not a real solution, it just hides the original bug.

Right, but we can’t fix the bugs and need to have the store running… so should I then report this as an official bug or has that already been handled?

James

 
Magento Community Magento Community
Magento Community
Magento Community
 
stengah
Member
 
Avatar
Total Posts:  42
Joined:  2008-07-17
Denmark
 

I just got this error as well - by adding upsales to one product - nothing else. I am using Magento 1.0.2.2 - removing the upsale option from the product cleared the error and I have just retested - this error is probably due to this:

- used a module to batch- relate multiple upsale options to a product
- in the popup where the items were entered I suspect I by writing habit added spaces between “item1, item2, item3” - where it should have been “item1,item2,item3”
- I recall the response dialogue in the admin backend listed the entry twice - as if these were entered twice
- then I got the error in front end - which makes sense in case in the spaces somehow were misinterpreted as values

When deleting upsell relations and redoing this the proper way (with “item1,item2,item3” as entries) - things worked out just fine with no errors…

Just for info in case anybody else experiences this issue.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mageho
Sr. Member
 
Avatar
Total Posts:  291
Joined:  2008-03-24
France, Paris
 
Michael - 02 October 2008 04:06 AM

If there are duplicate elements in the data that you are filling your collection with, that means that you getting that data in a wrong way. So the solution you posted is not a real solution, it just hides the original bug.

It is not one collection but several.
I call different collection of products for my modules : new products, bestsellers, best viewed, etc.

We can’t say that is duplicate products.

 
Magento Community Magento Community
Magento Community
Magento Community
 
QuadraVis
Sr. Member
 
Avatar
Total Posts:  82
Joined:  2008-05-30
D - Erbach
 
ryu007 - 25 January 2009 07:02 AM

Michael - 02 October 2008 04:06 AM
If there are duplicate elements in the data that you are filling your collection with, that means that you getting that data in a wrong way. So the solution you posted is not a real solution, it just hides the original bug.

It is not one collection but several.
I call different collection of products for my modules : new products, bestsellers, best viewed, etc.

We can’t say that is duplicate products.

I had the same error. The only thing i done: i moved a categorie from one tree to an other.
Moving the categorie back to its original place didn’t solved the problem.
So i modified the CORE-Code and now it works fine.

Thanks

BTW: i checked the database for this product_id as well as the product manager in Backend. The product_id was only once there! So i do not have a duplicate product.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageGuys
Guru
 
Avatar
Total Posts:  380
Joined:  2008-06-07
 

I was getting this error in the compare Block on several pages after logging in. After a bit of hunting I found that catalog_compare_item had a whole bunch of entries where the combination of visitor_id/customer_id, and product_id was not unique. I cleared the table (since it’s not really important long term data) and the problem is gone. What bothers me though is how it could have gotten into that state in the first place. shock

I have to say I’m kind of with the folks that say this should be ignored, rather than raising an error. Sure there is some underlying reason that there was a duplicate, but the correct behavior can be determined. This is because each entry in the collection should be unique, and entries with the same ID are identical. Ignoring the duplicates is the same as allowing them, and then removing duplicates, which also results in a correct final collection.

In my opinion errors (which are publicly visible to the user) should only be thrown in cases where the correct behavior can NOT be reliably determined. For all other cases the problem should be logged, but the program should behave itself. Remember that in the end, the most important thing to any site owner is sales. The visitor doesn’t want to know if the code tried to add duplicates to the collection. They want the site to behave itself, even if some programmer didn’t use something in the most acceptable way.

Perhaps there should be a debug mode and a special form of error for “best practice” errors like this? That way you could avoid the error in live stores but still have the error/callstack/etc. for the developers.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sakwoya
Jr. Member
 
Total Posts:  12
Joined:  2008-01-20
UK
 
Bug Slayer - 04 February 2009 11:28 AM

I was getting this error in the compare Block on several pages after logging in. After a bit of hunting I found that catalog_compare_item had a whole bunch of entries where the combination of visitor_id/customer_id, and product_id was not unique. I cleared the table (since it’s not really important long term data) and the problem is gone. What bothers me though is how it could have gotten into that state in the first place. shock

I’ve just hit this error when clicking on a product from a category view page - the only change in the store has been the addition of a number of upsells. Whether logged in or not - store displays a 404 error to the customer but logs the Exception in the var/report folder.

Clearing the table mentioned above did not help - instead I commented out the line 325 in lib/varien/Data/Collection.php as mentioned at the start of this post.

I would agree with the previous poster’s comments - why throw an Exception for this?
I would disagree with the Magento Team’s response earlier as we have not changed (in any way) the code that creates the Collections for this store.

public function addItem(Varien_Object $item)
    
{
        $itemId 
$this->_getItemId($item);
        if (!
is_null($itemId)) {
            
if (isset($this->_items[$itemId])) {
              
//  throw new Exception('Item ('.get_class($item).') with the same id "'.$item->getId().'" already exist');
            
}
            $this
->_items[$itemId] $item;
        
}
        
else {
            $this
->_items[] $item;
        
}
        
return $this;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
MageGuys
Guru
 
Avatar
Total Posts:  380
Joined:  2008-06-07
 

It has been a year since this thread started, and 9 months since the Magento Team looked at it. I’m surprised to hear that it is STILL unresolved, even though the thread is marked as solved. Could we get another look here? I really think that this can be put to rest using the suggested fix. At first glance the fix looks like a bad coverup, yes, but look carefully and you will see that it is not just an amateur hack; it is the right fix (or a close approximation of it.)

The core Magento code has had AT LEAST a couple of bugs (but most likely several bugs) that result in this error. Some of these bugs have never been tracked down and fixed. This code should NOT throw an error in production environments. It should quietly “do the right thing” anyway, and raise an error only in development environments.

Just to be clear, I’m totally against “hiding problems” but in this case, that is NOT what is happening. In this case an error is being thrown, when an assert should have been used, and that is also bad practice. The code will operate correctly regardless, because the collection guarantees that records are unique, even in this “error” case. Look at the code if you don’t believe me. The only possible impact of ignoring the problem is MAYBE on performance, and only in the cases where the current code will die. I say that “maybe slow in rare cases” is MUCH better than “dies in rare cases.” I’m sure every Magento user will agree. As written this IS a bug. This bug is making other minor and 100% recoverable bugs crash the system.

If anyone in the Magento team wants to discuss this fix, or any concerns with it. I’m happy to continue the discussion, either here, via PM, or by email.

 
Magento Community Magento Community
Magento Community
Magento Community
 
spice_mage
Jr. Member
 
Total Posts:  8
Joined:  2009-03-03
 

Hey ryu007,

That was indeed a life saver !!! I had been banging my head with this since the past “3” “DAYS” !!! And luckily I came across your post...and it worked !! Thanks a ton !! I hope this gets resolved by the next magento release.

Spice....

 
Magento Community Magento Community
Magento Community
Magento Community
 
Freddy Bang
Member
 
Total Posts:  52
Joined:  2009-02-04
 

I have upgraded to 1.3.2.2 latetly and in my catalogsale I get the exeption thrown when using the layered navigation.

Trying to remove the product with the id from the catalogsale listing doesn’t solve the problem just throws the exception for the next id in the list.

In the catalognew and all other lists the layered navigation works fine, so I stopped troubleshooting the problem and implemented the ‘stupid’ fix mentioned in this thread wink

Hopefully Varien will reopen this issue and get it fixed for once.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageGuys
Guru
 
Avatar
Total Posts:  380
Joined:  2008-06-07
 

I’ve posted this to the issue tracker (http://www.magentocommerce.com/bug-tracking/issue/?issue=7031) Hopefully this will help to get this fixed.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 3