I have a configuration reference, so there is a taxonomy with a field "content type" which references to any number of content types.
Only if I enter > 1 content type as reference I get an error message
Drupal\Core\Entity\EntityStorageException SQLSTATE[23000]: entity_usage Integrity constraint violation: 1062 Duplicate entry for key 'PRIMARY': INSERT INTO {entity_usage}
'0-node_type-352-taxonomy_term-de-0-entity_reference-field_refere' for key 'PRIMARY': INSERT INTO {entity_usage} (target_id_string, target_type, source_id, source_type, source_langcode, source_vid, method, field_name, count) 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
(
[:db_insert_placeholder_0] => event
[:db_insert_placeholder_1] => node_type
[:db_insert_placeholder_2] => 352
[:db_insert_placeholder_3] => taxonomy_term
[:db_insert_placeholder_4] => de
[:db_insert_placeholder_5] => 0
[:db_insert_placeholder_6] => entity_reference
[:db_insert_placeholder_7] => field_reference_content_type
[:db_insert_placeholder_8] => 1
)
in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save()</em> (line 829</em> of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).Probably Entity Usage must exclude saving data on Entity References to configurations to avoid this since they donnot have an unique target id.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | interdiff-5-7.txt | 1.52 KB | marcoscano |
| #7 | 2980089-7.patch | 1.63 KB | marcoscano |
| #5 | 2980089-5.patch | 969 bytes | marcoscano |
| #2 | reference_to_content_type.png | 21.26 KB | marcoscano |
Comments
Comment #2
marcoscanoCan you reproduce this in a clean install? If so, could you please share the steps to reproduce?
I've just tested it in a vanilla D8 that I have around, adding to a taxonomy term an entity_reference field pointing to a content type, and I did not see any error, and the usages seem to end up correctly in the DB:
So I wonder if I'm missing some important step to reproduce the bug.
Thanks!
Comment #3
marcoscanoAlso, moving to normal because you should probably be able to mitigate this by tweaking what is tracked and what not, in the configuration page.
Comment #4
demonde commentedMaybe I was not clear enough in the bug report.
The entity reference to "content type" is a multi value field and the error appears if I have two field values.
In your attached example above you have two different source id's but in my one the source id is identical.
Comment #5
marcoscanoOh I see what you mean now. Indeed, once the string id column in the DB is not a primary key, the SQL insert thinks it's a duplicate record.
Can you test if the attached patch solves the problem for you?
(Edit: Don't forget to go to /update.php and run the DB updates after applying the patch)
Comment #6
demonde commentedI applied the patch and updated and it works. I can now reference >1 field value per field at a configuration reference.
But on the update routine via drush I get an error message "Invalid use of NULL value":
Comment #7
marcoscanoOps, true, the new primary key cannot be NULL so we need to change that column too.
This should take care of that, let me know otherwise.
Thanks for the feeback!
Comment #8
demonde commentedI still got an update error so I ended up and simple reinstalled the module.
Comment #10
marcoscanoCommitted this for now, once it works for me without the error. Let's open a follow-up if anyone still experiences issues with this.
Thanks!
Comment #11
demonde commentedGreat, thanks!