I clicked on "Empty cart" owhen the cart has (0) items and got this error message.

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1: SELECT tmgmt_message.mid AS entity_id, :entity_type AS entity_type, NULL AS revision_id, :bundle AS bundle FROM {tmgmt_message} tmgmt_message WHERE (tmgmt_message.tjiid IN ()) ; Array ( [:entity_type] => tmgmt_message [:bundle] => tmgmt_message ) in EntityFieldQuery->execute().

I think there should be a validation for number of items in the cart before trying to execute the empty cart query, this will prevent MySQL errors.

Comments

mqanneh created an issue. See original summary.

mqanneh’s picture

mqanneh’s picture

StatusFileSize
new1.33 KB
mqanneh’s picture

Status: Active » Needs review
mqanneh’s picture

Version: 7.x-1.0-rc1 » 7.x-1.x-dev

Status: Needs review » Needs work

The last submitted patch, 3: pdoexception_when_trying_to_empty_cart-2629800-3.patch, failed testing.

The last submitted patch, 3: pdoexception_when_trying_to_empty_cart-2629800-3.patch, failed testing.

mqanneh’s picture

Status: Needs work » Needs review
berdir’s picture

Priority: Critical » Major
Status: Needs review » Needs work

Nice catch. I'd say this is major, not critical, since nothing is really broken after getting that error.

I don't think we need to introduce another message here. What would make more sense is to add an #access => count($job_items) or so to the delete button, so don't see it and it could only be an issue in case of race conditions with pressing the button multiple times or so.

mqanneh’s picture

Assigned: Unassigned » mqanneh

Good suggestion, I assigned the issue to myself to work on it and post an updated patch soon.

mqanneh’s picture

Status: Needs work » Needs review
StatusFileSize
new788 bytes

@Berdir check the updated patch for an alternative fix.

however, you can't rely on the count of items in the cart because it is always wrong.
you can check this issue that has a patch to fix number of items in the cart.
#2630104: Jobs number in cart is wrong

for this time you can test the last uploaded 2 patches ass these works fine - first patch (#2629800-3: PDOException: When trying to empty an empty cart) is better than the last one (#2629800-11: PDOException: When trying to empty an empty cart).

mpp’s picture

Nice catch, patch in #11 seems to work fine.

In Drupal 8 this is solved by always keeping the "empty cart" link visible. When clicking it, you get the message: "All job items were removed from the cart.".

The tests on the 7.x dev branch seem to fail.

mqanneh’s picture

@mpp if it worked for you can you update the ticket status to RTBC

mpp’s picture

Status: Needs review » Reviewed & tested by the community

  • Berdir committed 2dc4d93 on 7.x-1.x authored by mqanneh
    Issue #2629800 by mqanneh: PDOException: When trying to empty an empty...
berdir’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed, not sure about #12, seems like this might make sense in 8.x too.

mqanneh’s picture

@Berdir

check this issue
https://www.drupal.org/node/2630104

It might be related and needs to committed as well

mqanneh’s picture

@Berdir I rerolled the patch in #11 against the latest dev version of 8.x-1.x.