We have the following use case:

A node type with a multi-value entityreference field that references users.
The users listed on a node are the ones responsible for the node, so they all should have update permissions on the node.

We use standard drupal node access for that.
View access to the node type is arranged on role level.

On creation of a node with duplicate entries in the list of responsible users we get the following PDOException:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '7970-3-responsible' for key 'PRIMARY': INSERT INTO {node_access} (nid, realm, gid, grant_view, grant_update, grant_delete) 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, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11); Array#012(#012 [:db_insert_placeholder_0] => 7970#012 [:db_insert_placeholder_1] => responsible#012 [:db_insert_placeholder_2] => 3#012 [:db_insert_placeholder_3] => 0#012 [:db_insert_placeholder_4] => 1#012 [:db_insert_placeholder_5] => 0#012 [:db_insert_placeholder_6] => 7970#012 [:db_insert_placeholder_7] => responsible#012 [:db_insert_placeholder_8] => 3#012 [:db_insert_placeholder_9] => 0#012 [:db_insert_placeholder_10] => 1#012 [:db_insert_placeholder_11] => 0#012)

We wrote a small patch on entityreference_field_validate that throws an error if a duplicate is detected.
So we left it up to the user to resolve the conflict.

The other option would be to resolve it automatically.
We leave this to the maintainers of this module.

Files: 
CommentFileSizeAuthor
entityreference-duplicate-entries.patch954 bytesJan van Diepen
PASSED: [[SimpleTest]]: [MySQL] 114 pass(es).
[ View ]

Comments

amitaibu’s picture

Status:Needs review» Postponed (maintainer needs more info)

Sorry, I don't understand how you gor the duplicate errors. Do you have steps to reproduce?

Jan van Diepen’s picture

We just reference the same user twice on a multi-value entityreference field. Entityreference will try to add the same user twice which will lead to the 1062 Duplicate entry PDOException. The patch on form_validate will display an error message on submission of the form. To automate this any duplicate references should be removed before actual submission.

regedite’s picture

Status:Postponed (maintainer needs more info)» Needs review
Rob_Feature’s picture

I'm actually seeing this same error, but for the file_managed table while running a drush function (drush geocoder-backfill). I'm not sure how it's related, but wanted to chime in that I'm seeing it too....

array_flip(): Can only flip STRING and INTEGER values! entity.inc:178                                                                                          [warning]
WD node: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (filemime, filesize, [error]
status, timestamp, type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3,
:db_insert_placeholder_4); Array
(
    [:db_insert_placeholder_0] => application/octet-stream
    [:db_insert_placeholder_1] => 0
    [:db_insert_placeholder_2] => 1
    [:db_insert_placeholder_3] => 1349983614
    [:db_insert_placeholder_4] => undefined
)
in drupal_write_record() (line 7036 of /var/www/vhosts/drupal/includes/common.inc).