The function taxonomy_select_nodes() adds a condition to field tid of table taxonomy_index. Unfortunately the table alias is not added so if you alter the query (i.e. by implementing hook_query_node_access_alter()) and add your own condition with another tid, the query horribly fails: "Integrity constraint violation: 1052 Column 'tid' in where clause is ambiguous ...".
Patch follows ...
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 2574003-5_test-only.patch | 2.63 KB | poker10 |
| #5 | 2574003-5.patch | 3.17 KB | poker10 |
| #2 | missing_table_alias-2574003-2.patch | 548 bytes | stborchert |
Comments
Comment #2
stborchertThe patch simply adds the table alias for taxonomy_index.
Comment #3
poker10 commentedThe patch still applies to the 7.x-dev and it is working. Bug can be clearly reproduced by adding a simple join in the
hook_query_node_access_alter():You will get:
Setting this as RTBC.
Comment #4
mcdruid commentedIs this a problem in D9?
Can we add #3 to the existing tests easily?
Comment #5
poker10 commentedThis does not seems to affect D9 -
taxonomy_select_nodes()was removed and replaced by view in #2384583: Remove taxonomy_select_nodes function and related issues.The views query in D9 looks like this (there are table aliases correctly set):
I have added the test based on that example. Patch itself is unchanged.
Note that I have to create a new taxonomy_nodes_test.module and was unable to use the existing taxonomy_test.module for the new hook, because term_view alter hooks in the taxonomy_test.module are not controlled by a variable and because of that taxonomy term detail page throws
undefined propery $term->antonymwhen testing this scenario and displaying that page.Comment #7
mcdruid commentedExcellent, thanks for the D9 explanation and the tests!
Comment #9
poker10 commentedThanks!