If you add 2 products to your cart, go to /cart and click both the remove buttons before the page reload(because you pressed the first remove). The cart session becomes corrupt and you cant access anypage with the cart on it without getting this fatal error:
EntityMetadataWrapperException: Unable to load the commerce_line_item with the id <commerce_line_item id>. in EntityDrupalWrapper->value() (line 696 of <drupal_root>/sites/all/modules/entity/includes/entity.wrapper.inc).
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 0001-Rewrote-commerce_entity_reference_delete-to-avoid-us.patch | 2.78 KB | serialjaywalker |
Comments
Comment #1
j0rd commentedSame problem, but for me, I'm pramatically clearing the items in my cart (commmerce_cart_order_product_line_item_delete) before adding a new line_item (commerce_product_line_item_new) in a custom add to cart page I've made.
Comment #2
j0rd commentedHere's how I have to clear from carts to get it to work.
That's a little silly, as only doing one of them will completely break your store and leave it in an invalid state which needs to be fixed by manually deleting entries from the database then clearing cache.
Here are those entries
I would like to know if this is the proper way to clear the cart, or if there are other functions I should be using. I tried these two as they have function names which related to what I'm trying to accomplish.
Comment #3
serialjaywalker commentedI believe this is a duplicate of #1186130: Line item deletion causes EntityMetadataWrapperException, itself marked as a duplicate of #1135182: Error message EntityMetadataWrapperException: Unable to load the commerce_product with the id 5053. in EntityDrupalWrapper->valu (but I'm not convinced those two are the same).
Comment #4
serialjaywalker commentedAs far as I can tell, this problem arises because commerce_entity_reference_delete() uses the Entity API classes which require us to load the (already deleted) line item in order to delete the reference to it.
The attached patch rewrites commerce_entity_reference_delete() to avoid using the Entity API classes. I'm not so experienced with Commerce that I'm sure that this is the best way to fix the problem, but this does seem to fix the problem (at least when deleting with the Line Item Manager widget), so I wanted to put this on the table.
Comment #5
serialjaywalker commentedAh, scratch that. I decided that this is actually a completely different issue. I'll put my patch where it belongs.
Comment #6
rszrama commentedYeah, the multiple remove button clicking error is one I've turned up in the past as well. I suppose if it comes down to it we can just lock all remove buttons on the View once one is clicked, but that feels a little brute force and would be JS dependent... I just fear that there may be something in our database query transactioning that causes the requests to collide and screw the order up. Of course, we could just try to get a fix in the Entity API to not choke when a wrapper finds a reference to a non-existent entity.
Edit: looks like I opened an issue for this a while ago. Just updated it: #1030140: Do not throw exceptions when wrapping an entity with a stale reference
Comment #7
rszrama commentedCan I get some tests on the bug here with the latest dev version? In local testing, I cannot reproduce the bug any more... I know I was getting it before vacation, but one of the first commits I made when I got back addressed the function that may have been at the bottom of this: commerce_entity_reference_delete().
Comment #8
sirtetJust downloaded kickstart through drush, web-installed, added all three sample-products to the cart, and clicked all "remove"-buttons before the first reload. this brought me to a blank page with only the following text:
"Commerce Kickstart" is a Link to the Homepage, clicking it brought the next error and a success message:
every following click, and manually going to the Homepage reloaded the same error.
so i tried to go to /user. Same result.
So i went back in History to the Cart. Worked. Reloading the cart brought the error back.
going back in history worked.
then i logged out, and the error was gone.
i repeated the whole procedure, and this time, i couldn't get rid of the error, even after logging out.
[INTERMISSION]
[/INTERMISSION]
only clearing browser cache removed the error.
(this was on WIN7, Chrome13)
with FF5 and IE9 i never got an error, however fas t tried to click...
Comment #9
rszrama commentedYou'll always be logged in after installation, so no mystery there. We're curious to know if the patch in #1243306: Implement pessimistic entity locking and enable it for orders resolves this issue. Can you first update to the latest -dev and try to duplicate the error again? Then can you install that patch and still duplicate the process that made it fail?
Comment #10
rszrama commentedI should've left this in needs review. I can't reproduce this bug any more using -dev and that patch I linked. Just looking for validation.
Comment #11
sirtettoo newbie to be sure about needed steps, so i document:
drush dl commerce --select --> selected 7.x-1.x-dev - 2011-Aug-10 --> success
drush updatedb --> No database updates required
drush cc all --> 'all' cache was cleared
Now i tried Safari and FF5.01 on OS10.6, can't get the error, got confirmationpages with up to 3 simultaneously deleted items.
But on WIN7 CHROME13 it's still here.
Since i can get rid of the Error only by deleting cookies, would't it be a good idea to have a mechanism in this type of Error-Message Routine, to delete cookies if a user saw n Errors in a Row or so? Or at least a text message to clear cookies (which at best will let many ppl run into the kitchen).
next:
wget http://drupal.org/files/issues/1243306-commerce-locking.patch
patch < 1243306-commerce-locking.patch
result:
ok, maybe patch applies to rc1?
drush dl commerce --select --> 7.x-1.0-rc1 - 2011-Jul-14
--> Install location... ..../sites/all/modules/commerce already exists. Do you want to overwrite it? (y/n): y
hmm, i did not get asked installing the dev-version, why that?...
however, i continue:
wget again,
patch again,
--> patching fails same way.
what next?
Thomas
Comment #12
rszrama commentedYou might try
patch -p0 < 1243306-commerce-locking.patch.Comment #13
sirtetnever got the patch to work.
But i did read in the issue with the patch (http://drupal.org/node/1243306), that an update to Drupal Core 7.x dev would now solve the "multiple remove error".
Trying to update the core, i destroyed my installation. So i did a fresh install with kickstart, which installed DC 7.x-1.0-rc3.
Now i can't reproduce the error anymore.
Comment #14
rszrama commentedWell, if no one else has any objections, I'm going to mark this one fixed thanks to the issue I linked to in comment #9 above. I still can't reproduce any problems here, and it seems to have been solved by the update to 7.x for the only person to get the error (probably do to unrelated db_transaction() problems). We can reopen this if necessary.
Comment #16
sirtetNot sure it that belongs in this issue, the error is different:
I used the quickstart ubuntu-VM (http://drupal.org/project/quickstart)
and installed D7.8 with profile from commerce_kickstart 7.x-1.0-rc1
add different items to cart, and then click several remove's before page reloads...
Comment #17
rszrama commentedYeah, that should go in a separate issue reported on the Commerce Stock project.