Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
Indexing with a nested taxonomy causes an SQL error of the following form:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '20' for key 'PRIMARY'
Re-creation
Drupal Set-Up
Fresh Copy of Drupal 7.25
Installed:
Entity API 7.x - 1.3
Database Search 7.x - 1.2
Search API 7.x - 1.11
Search Views 7.x - 1.11
Views - 7.x - 3.7
Chaos tools 7.x -1.3
Re-creation in Drupal
- Create a new Taxonomy.
- Add a number of values.
- Create a nested taxonomy from those values i.e.
- Add a taxonomy field to article
- Create several articles give them various values for your nested taxonomy
- Create a search database.
- Create a search index.
- Add taxonomy and title to the fields to be indexed.
- Enable index hierachy.
- Select "All Parent terms" for the taxonomy field you just created.
- Run the index and you should discover the articles with taxonomy values are not indexed.
A
B
C
D
F
G
H
J
Comment | File | Size | Author |
---|---|---|---|
#6 | 2174163-6--callback_form_submit_field_changes.patch | 1.67 KB | drunken monkey |
Comments
Comment #1
drunken monkeySee #2173277-1: Creation order can cause Taxonomy Field to never appear in views sort – I cannot reproduce this, but something seems to have gone wrong when enabling "Index hierarchy". Be sure to use the latest module versions, try to disable and re-enable the data alteration, clear the caches – this should definitely work fine (and both problems have the same root cause).
Comment #2
splitsplitsplit CreditAttribution: splitsplitsplit commentedHmm ok, I'll take another look at this and see if I can narrow down where the error was. Perhaps it was some sort of memcache error I forgot to clear.
Somewhere along this debugging I found two of my fields were corrupted, which I thought I'd separated from this, but I'll give it another go. Thanks for trying to re-create it!
Comment #3
splitsplitsplit CreditAttribution: splitsplitsplit commentedI've had to come back to this problem recently. I've managed to re-create it again, I was hoping if I gave more detailed instructions it would be replicable.
This time I've built it on a local environment (XAMPP) (rather than a full VM Box in the hopes it's slightly more replicable.)
The instructions are pretty much the same as above but I used the latest modules and added slightly more detail:
XAMPP: 3.2.1
Fresh Copy of Drupal 7.31
Installed:
Entity API 7.x - 1.5
Database Search 7.x - 1.4
Search API 7.x - 1.13
Search Views 7.x - 1.13
Views - 7.x - 3.8
Chaos tools 7.x -1.4
Flushes the caches and re-enabling everything is doing nothing. I was hoping you could check one more time, because I can't get any other result.
Comment #4
splitsplitsplit CreditAttribution: splitsplitsplit commentedComment #5
splitsplitsplit CreditAttribution: splitsplitsplit commentedCreated a 4 minute video of re-creation (from fresh install to problem). Un-enabling and re-enabling always works on test and occasionally on live. I'm hoping the guaranteed break first time is enough to diagnose problem otherwise might have to close again.
https://www.dropbox.com/s/i3w9ud8x9snaf6h/tax_bug.swf?dl=0 (it's a swf file, so it should open in a browser.)
Comment #6
drunken monkeyAh, sorry, should have commented earlier! The video wasn't necessary, I already managed to reproduce this a few hours ago, I was just working on the patch. But thanks a lot for going to that additional trouble to help analyze this issue!
To the issue itself: I now found out that the critical piece here is that the taxonomy term reference field has to be single-valued! Because then, using the "Index hierarchy" data alteration on it will change it's type to a list, but it seems the Search API doesn't realize that because the code checking for changes in the submit function for that form assumes all data alterations only add properties, not modify existing ones.
The fix is therefore to just spot this better, or rather, to err on the safe side and just re-compute the fields whenever that form is submitted. Patch attached, please test whether that solves your problem!
Comment #7
splitsplitsplit CreditAttribution: splitsplitsplit commentedNo problem, it's not quite as useful as actually being able to solve it, but I'm slowly making the jump from QA to dev.
The patch works and clears up all the issues on my clean builds. Frustratingly it doesn't seem to fix it on my production server, although I have found that though it always fails first time, if you index it without the field and then re-apply it, it seems to work the second time.
I can't recreate this though on my clean build, so we might just have to close this one as fixed.
Comment #8
drunken monkeyHm, too bad it doesn't fix the production servers, too. Probably something wrong with the internal configuration there, then. Good that you at least have a workaround.
And good to hear the patch works at least for clean builds, that seems to be a good step then, at least. Thanks a lot for testing!
Committed.