I have a lot of nodes tagged with various taxonomy terms. But for some reason, they are not showing, and instead I am getting the error:

There is currently no content classified with this term.

This has always worked. I was just getting ready to roll out the update (current site on D7) but had to stop because most of the pages are generated with taxonomy terms.

Accepted answer

In the Backdrop site.

OK, thanks. I will create an issue. 

ETA: Follow up at https://github.com/backdrop/backdrop-issues/issues/6082

Most helpful answers

Also, you may want to run both:

taxonomy_delete_node_index($node);

taxonomy_build_node_index($node);

 

To avoid trying to insert records in the DB that already exist.

Check the file taxonomy.settings.json in your files/config_XXX folder to see if the property maintain_index_table is set to true. If not, make it true.

Then you can manually run taxonomy_build_node_index() in a loop, passing to it all of the nodes in your site one by one. You can do, for example, a db_select to get all the node ids, and then a node_load_multiple() to load them and loop through them.

That should rebuild taxonomy_index.

The reason why that table is incomplete... I don't know. Something must have happened upon upgrading the site.

Sorry to hear that! It'd be helpful to know if you have any taxonomy term related contrib modules in your D7 site.  

Can you inspect the taxonomy-related tables in the DB? Check taxonomy_index (which maps term's tid to node's nid) and also taxonomy_term_data (in this last one, check that in Backdrop's DB, the vocabularies are machine names, and that those exist in the config folder).

Comments

I don’t have the full answer but this sounds like something that somebody else I was helping discovered. If you load and save a random tagged node without changing anything, does it then show up on the term page? I think the workaround on the other site is currently to run “resave nodes” (module) after the upgrade process to do that in bulk.

But it would be good to know why that happens so it could be prevented in the first place…

Thanks for the suggestion. I tried it, and no, the re-saved node still doesn't appear.

Sorry to hear that! It'd be helpful to know if you have any taxonomy term related contrib modules in your D7 site.  

Can you inspect the taxonomy-related tables in the DB? Check taxonomy_index (which maps term's tid to node's nid) and also taxonomy_term_data (in this last one, check that in Backdrop's DB, the vocabularies are machine names, and that those exist in the config folder).

No, I don't have any taxonomy-related contrib modules in the site.

Yes, I will look at the DB tables and post here after that.

The taxonomy_index table is missing a majority of nodes even though the nodes (when I edit) show the taxonomy term tags. Looks like this is the source of the problem. Is there a way to rebuild this table? I'm going to go back and look at the backup from right after I upgraded from D7 and also at the D7 tables.

In the taxonomy_term_data table, the expected tid's are there, and the vocabulary values are machine names. There are config json files for each of those vocabularies in the config directory.

Check the file taxonomy.settings.json in your files/config_XXX folder to see if the property maintain_index_table is set to true. If not, make it true.

Then you can manually run taxonomy_build_node_index() in a loop, passing to it all of the nodes in your site one by one. You can do, for example, a db_select to get all the node ids, and then a node_load_multiple() to load them and loop through them.

That should rebuild taxonomy_index.

The reason why that table is incomplete... I don't know. Something must have happened upon upgrading the site.

Also, you may want to run both:

taxonomy_delete_node_index($node);

taxonomy_build_node_index($node);

 

To avoid trying to insert records in the DB that already exist.

OK, so I did as you suggested, but it still doesn't work. Looking at the DB table from MariaDB, I see that the taxonomy_index table is now empty.

Yes, I did check the files/config_XXX/active/taxonomy.settings.json file.

$ cat taxonomy.settings.json 
{
    "_config_name": "taxonomy.settings",
    "maintain_index_table": true,
    "terms_per_page_admin": 100
}

So it looks like taxonomy_delete_node_index($node) worked, but taxonomy_build_node_index($node) didn't.

I am now thinking of a hacky solution like loading up the table from one of my backup DB dumps.

So I did some debugging and I think I found the problem. The taxonomy terms field info gives the module as "entityreference" rather than "taxonomy".

When you asked me whether I have any taxonomy term related contrib modules in my D7 site, I looked through the modules page but this module (Entity Reference) didn't mention anything about taxonomy. It didn't occur to me that it might be related. Sorry about that.

Of course it is a core module in Backdrop since 1.23. 

I did also finish looking through the backups, and found that the taxonomy_index table was fine after upgrading to Backdrop, and actually fine as late as the end of March.

If the handling is in core now, shouldn't it still work? i.e. the upgrade path should have handled any relevant DB updates? I'm not sure how to fix this. Help?

This sounds like a bug.

You say "The taxonomy terms field info gives the module as "entityreference" rather than "taxonomy"."  Are you referring to the info in Backdrop or in the Drupal 7 site?  I think that may offer some clues.

If you are able to create an issue in the queue, that may also help others see this, and possibly help fix this.