Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Developer experience
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
21 Jul 2011 at 18:02 UTC
Updated:
28 Aug 2011 at 22:41 UTC
Hi,
that's 2 days I'm fighting this issue, and I desesperate!
I've seen this issue http://drupal.org/node/1060002, which seems to be related, but error is still there even if the patch has been commited as you can read.
Here is the code which leads to the error :
<?php
/**
* Implemente hook_menu().
*/
function mymodule_menu() {
$menu=array();
$menu['mymodule_test'] = array(
'title' => 'Test',
'page callback' => 'mymodule_test',
'access callback' => TRUE,
'weight' => 7,
);
return $menu;
}
function mymodule_test(){
global $user;
// we load the first product
$product=commerce_product_load(1);
// then we create a line item
$line_item = commerce_product_line_item_new($product,2);
// we save it
commerce_line_item_save($line_item);
// and we add it to the cart
commerce_cart_product_add($user->uid, $line_item,TRUE);
// we go for another product
$product2=commerce_product_load(2);
$line_item2 = commerce_product_line_item_new($product2,2);
commerce_line_item_save($line_item2);
commerce_cart_product_add($user->uid, $line_item2,TRUE);
// and we remove this lines
$order = commerce_cart_order_load($user->uid);
$order=commerce_cart_order_product_line_item_delete($order, $line_item->line_item_id,TRUE);
$order=commerce_cart_order_product_line_item_delete($order,$line_item2->line_item_id,TRUE);
// at the end, we save (tries with saving each time gave the same error)
commerce_order_save($order);
return "ok";
}
?>
Note that if I deal with only one line (create then remove), all is fine. The error only occurs when I try to deal with two lines, and occurs on the second line deletion.
Removing the rollback when catching the exception shows that the line is indeed removed, but somewhere commerce tries to load the line item.
Anybody seeing what I've done wrong?
Regards,
TahitiClic
Comments
Comment #0.0
tahiticlic commentedTypo correction
Comment #1
tahiticlic commentedIn commerce.controller.inc, maybe the
block should come prior to the db_delete.
I did this modification and it works well now, I guess that's a deletion priority between references taht must be deleted first and entity itself that must be deleted last.
Comment #2
j0rd commentedI ran into the same issue as you.
http://drupal.org/node/1228502#comment-4792490
We need a more clear way to clear the cart.
At the very least commerce_cart_order_product_line_item_delete() should not leave the database in an inconsistent state.
Comment #3
tahiticlic commentedYes, that's embedded in the commerce_cart_order_product_line_item_delete call. The problem is deeper, in commerce controller (even if I can't see why this works if you remove only one line).
Comment #4
rszrama commentedAny reason you can't use commerce_cart_order_empty()? Also, I think the error may have been resolved by this recent commit if you could pull and try again.
See: http://drupalcode.org/project/commerce.git/commitdiff/b3b9bdf (this removes the entity metadata wrapper from commerce_entity_reference_delete())
Comment #5
j0rd commentedI wasn't aware of that function which is why I wasn't calling it. I needed to remove some line items, so I was using that when grepping the code.
With that said, running any function hopefully shouldn't leave the database in a broken state. It should either keep things working or not do anything.
I'll test this out next week.
Comment #6
rszrama commentedYeah, the problem is primarily with entity_metadata_wrapper(), which tries to load a referenced entity when it wraps an entity with a reference property / field. I agree that it shouldn't cause a site to go down to have a stale reference. Apparently I opened #1030140: Do not throw exceptions when wrapping an entity with a stale reference a while ago to address this but never got back with fago; I've updated the issue and would appreciate it if you could chime in there with your experience as well.
fwiw, http://api.drupalcommerce.org may help with finding API functions. I think it needs some more love (I don't like the URLs it generates atm, for example), but all of our APIs are documented and our hooks are all documented through there or through the specification handbook on dc.org itself.
Comment #7
rszrama commentedIn trying to duplicate this issue, I can no longer generate the error. I think this is fixed, though #1243306: Implement pessimistic entity locking and enable it for orders seems to be turning up different issues with a new approach to transactions. The safe thing to do will still be to use the empty function, and I won't commit that other patch until I'm sure it accommodates this example.
Comment #8
rszrama commentedAnd it turns out the error in there is a bug in Drupal 7.7 that has already been fixed in dev. I'm going to go ahead with that patch, and if you run into an issue with transaction collision, you just need to update to dev until Drupal 7.8+ comes out (early September at the latest).
Comment #9
tahiticlic commentedWell thanks for the solution, I was looking for a transaction problem not beeing able to trace it deeply though.
I can't upgrade Commerce now, the project is (lately) delivered and API changes may break our modules. But I'll test it during the next whole upgrade.
Comment #10
zeta1600 commentedsubscribing.
still getting this error on Drupal 7.x-dev.
I have a rule to remove product if >1 quantity.
Comment #11
rszrama commented@zeta1600 - I'm going to need you to post your Rule up in here. And can you specify the exact error message?
Comment #12
zeta1600 commentedThanks for reply rszrama.
My rule is as follows:
Rule:
Event: After adding a product to the cart
Conditions:
User has role(s)
Parameter: User: [site:current-user], Roles: Level 1
Total product quantity comparison
Parameter: Order: [commerce_order], Operator: >
Action:
Remove all products from an order
Parameter: Order to empty: [site:current-cart-order]
I was getting this error:
EntityMetadataWrapperException: Unable to load the commerce_line_item with the id 64. in EntityListWrapper->value() (line 934 of /Users/..../sites/all/modules/entity/includes/entity.wrapper.inc).
But then, I realized you didn't want D7 updated, you wanted DC to dev version. So, I did and cleared cache. Now, I get this error:
PDOException: There is already an active transaction in db_transaction() (line 2479 of /Users/.../includes/database/database.inc).
I have reverted back to D7.7 and DC 7.x-1.0-rc1
Hope you can help.
Comment #13
zeta1600 commentedInterestingly enough, after reverted and then re-uploaded DC dev again and NOT clear D7 cache, it works fine... hmmm.
Comment #14
zeta1600 commentedNo... I was wrong, I am still getting this error:
PDOException: There is already an active transaction in db_transaction() (line 2479 of /Users/.../includes/database/database.inc).
Comment #15
rszrama commentedIf you're using Commerce dev (soon to be RC2) and you're getting this error, you need to use Drupal 7.x-dev, not Drupal 7.7.
Comment #16
zeta1600 commentedYup, DC dev and D7 dev worked fine. Thanks.
Comment #17
rszrama commentedAwesome, glad to hear it. : )
Comment #18
arbel commenteddon't want to hijack this queue but I'm getting this error with the latest d7 dev and DC-rc2.
I've got the commerce coupon module installed (and commerce shipping).
when I enter an invalid coupon code on the checkout pane, I get a validation error message as expected that the coupon code is invalid. all good up to this point.
now if I try to submit the checkout pane again, with no coupon code, correct coupon code or invalid coupon code, I get:
EntityMetadataWrapperException: Unable to load the commerce_line_item with the id
I'm not really sure what the cause is or how I should go about debuggin this.
Idan
Comment #19
rszrama commentedPerhaps the Coupon module is using a line item for coupons and not deleting them properly? I haven't peeked into the Coupon code, so I'm not really sure where you should begin researching it.
Comment #20.0
(not verified) commentedCorrection on code