In apachesolr_get_parent_terms(), a call to db_rewrite_sql() declares the primary table as "t". This is assumed by other modules to be an alias for the table term_data.
That in turn means that other modules hook_db_rewrite_sql() understandably add conditions on database columns like t.vid, which doesn't exist on the term_hierarchy table.
An example is Domain Taxonomy Access, which generates the following error:
User warning: Unknown column "t.vid" in "where clause" query: SELECT DISTINCT t.tid, t.parent FROM term_hierarchy t LEFT JOIN domain_taxonomy_access dta ON dta.tid = t.tid WHERE ((dta.grant_view >= 1 AND ((dta.gid = 0 AND dta.realm = "domain_site") OR (dta.gid = 6 AND dta.realm = "domain_id"))) OR t.vid IN(2,3,4,5,1,7,6,8)) AND ( t.tid IN (97)) in _db_query() (line 147 of /var/www/drupal6-wrap/includes/database.mysqli.inc).
This can be fixed by re-aliasing the term_hierarchy table as e.g. "th", which DTA doesn't know about.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | apachesolr-1186830-6.patch | 779 bytes | Yaron Tal |
| #1 | 1186830-apachesolr-term-hierarchy-sql-rewrite-bug.patch.txt | 724 bytes | jp.stacey |
Comments
Comment #1
jp.stacey commentedPlease find attached a patch against 6.x-1.2 (It's an older version, but it's the one we're currently using on this client site.)
(This work sponsored by Torchbox.)
Comment #2
pwolanin commentedComment #3
jpmckinney commentedHarmless. Committing. Thanks!
Comment #5
Yaron Tal commentedWouldn't it be better to add the term_data table to the query and keep t as the primary table? That way db_rewrite_sql still would make a difference. By using th modules like Domain Taxonomy Access will need to either add th to their hook or won't work on the Solr block.
Making it:
Comment #6
nick_vhDo you have a patch and a way for us to reproduce the issue? This issue was already fixed and closed so re-opening without a good intro is hard for others to follow.
So :
Show the limitations from the current implementations
Show a way to reproduce a problem
Show your proposed solution
Comment #7
Yaron Tal commentedWell the limitation is that by using term_hierarchy (th) as the primary table instead of term_data (t) modules like Domain Taxonomy Access will need to either add th to their hook or won't work on the Solr block. By not working on the block, I mean that they won't be able to filter out the terms, and thus leave terms visible to users who shouldn't have access to them.
To reproduce the problem:
Install the Apache Solr module and Domain Taxonomy Access. Enable a taxonomy filter, and disallow users to see some of the terms.
The terms will still be visible in the block, because the apache solr module is using th as the primary table, and DTA expects all modules that select terms to use t as the primary table.
A solution would be to patch the DTA module and all modules that use hook_db_rewrite_sql() to add their changes if the main table is th.
Another solution which I proposed 2 comments up would be to patch the apache solr module to use t as the primary table instead of th. This would need a JOIN in the query, which is a bit of overhead, but it would make rewriting the sql a lot easier.
I attached a patch to demonstrate what I meant.
Comment #8
nick_vhComment #9
nick_vhThis should be fixed in 6.x-3.x. Closing the issue, better to maintain a new version
Comment #10
Yaron Tal commentedThen I guess 1.x will soon be updated to get the status un-maintained? And the 3.x beta-1 version will become stable?
If bugfixes like this don't even make it to the 1.x range.