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

  1. Create a new Taxonomy.
  2. Add a number of values.
  3. Create a nested taxonomy from those values i.e.
  4. A
        B
        C
        D
    F
        G
        H
        J
    
  5. Add a taxonomy field to article
  6. Create several articles give them various values for your nested taxonomy
  7. Create a search database.
  8. Create a search index.
  9. Add taxonomy and title to the fields to be indexed.
  10. Enable index hierachy.
  11. Select "All Parent terms" for the taxonomy field you just created.
  12. Run the index and you should discover the articles with taxonomy values are not indexed.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drunken monkey’s picture

Status: Active » Closed (cannot reproduce)

See #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).

splitsplitsplit’s picture

Hmm 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!

splitsplitsplit’s picture

I'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

  1. Create a new Taxonomy.
  2. Add a number of values.
  3. Create a nested taxonomy from those values i.e.
  4. asia
        china
        japan
        thailand
    europe
        france
        germany
        spain
    
  5. Add a taxonomy field to article
  6. Create 6 articles, I gave each article a child value from the taxonomy. No parent values.
  7. Create a search database.
  8. Create a search index.
  9. Add taxonomy and title to the fields to be indexed.
  10. Enable index hierachy.
  11. Select "All Parent terms" for the taxonomy field you just created.
  12. Run the index and you should discover the articles with taxonomy values are not indexed.

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.

splitsplitsplit’s picture

Status: Closed (cannot reproduce) » Active
splitsplitsplit’s picture

Created 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.)

drunken monkey’s picture

Status: Active » Needs review
FileSize
1.67 KB

Ah, 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!

splitsplitsplit’s picture

No 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.

drunken monkey’s picture

Status: Needs review » Fixed

Hm, 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.

  • drunken monkey committed fc4c7f5 on 7.x-1.x
    Issue #2174163 by drunken monkey: Fixed detection of field type changes...

Status: Fixed » Closed (fixed)

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