The dedupe function does not properly detect duplicates when used on a field value that is falsy, e.g. `0`.
As a result, PDOExceptions may occur due to duplicate keys:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'sku': INSERT INTO {commerce_product} (revision_id, sku, title, type, language, uid, status, created, changed) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( /* MYDATA */ ) in drupal_write_record() (Zeile 7333 von /srv/www/htdocs/MYPROJECT/html/includes/common.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ckaotik created an issue. See original summary.

ckaotik’s picture

Attached patch to replace `fetchField()` with `rowCount() > 0`. Also removed `$candidate_found` assignment since it was not used anywhere else.

ckaotik’s picture

Status: Active » Needs review
joelpittet’s picture

Version: 7.x-2.8 » 7.x-2.x-dev
Status: Needs review » Reviewed & tested by the community

That's a good call! RTBC++. It doesn't apply against dev but it's only 2 lines

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 2: handlededupe_on_falsy-2630862-2.patch, failed testing. View results

pifagor’s picture

FileSize
739 bytes

I recreated patch.

pifagor’s picture

Status: Needs work » Needs review
alex_optim’s picture

Status: Needs review » Reviewed & tested by the community

Patch good work for me.

pifagor’s picture

  • pifagor committed 31877d9 on 7.x-2.x
    Issue #2630862 by ckaotik, pifagor, joelpittet, alex_optim: handleDedupe...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.