I hunted the bugs that recently caused a lot of tests to fail on drupal.org and travis.com in search_api, facets and search_api_solr.
From my point of view the solution that has been committed in #2775437: Fix the tests is wrong!
\Drupal\search_api\Plugin\views\filter\SearchApiTerm extends \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid without declaring a dependency to the taxonomy module. Since Drupal's plugin system will always load all registered plugin classes' files when discovering plugin definitions (i.e., after a cache clear), this will produce a fatal error on all pages with views, even if our taxonomy term filter is never actually used anywhere.
It's the wrong approach to declare these dependencies in the test modules. The correct solution would be to move these plugins into separate sub-modules that explicitly declare the dependency to the taxonomy or the user module!
Steps to reproduce
- Enable Taxonomy
- Enable Search API
- Disable Taxonomy
Now you have a fatal error on every page with a view.
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | 2777483-34--views_taxonomy_handlers_dependencies.patch | 15.29 KB | drunken monkey |
Comments
Comment #2
borisson_@mkalkbrenner: it might be useful to have a look at #2668236: Make the plugin discovery case sensitive for the case sensitivity.
I feel very strongly that we should't let search api depend on taxonomy, maybe we should put the term stuff in a seperate module that does depend on taxonomy?
Comment #3
mkalkbrennerThat's what I proposed, too:
Comment #4
borisson_Oh, oops, yes. That solution++
Comment #5
drunken monkeyI'm not sure I agree with this. If the taxonomy or user module isn't enabled (not possible for the latter, I think), there won't be field references to taxonomy terms (or users), so the filters won't be used anyways.
Of course, you can cause a fatal error by still requiring the file manually – but why would you do that? With that logic, we also couldn't provide a Views integration without depending on the Views module. But if the Views module isn't installed on a site, all those classes depending on it just won't be used – problem solved.
If you show me a way to actually trigger this problem via the UI, then yes, that would be a problem. Then we'd probably need to make sure to declare the necessary dependencies for views using those filters, for example. (Or remove the filter class via
hook_views_filter_alter()(or whatever the hook is) if the module isn't enabled.)But if you can only trigger it with special PHP code, it's not a bug.
Also, even if it is a bug, I don't really see why it should be a Beta blocker? It won't require any API change to fix it, as far as I can see?
Comment #6
mkalkbrennerUnfortunately that's easy :-(
Now you have a fatal error on every page!
Comment #7
drunken monkeyOh, wow, that indeed blows up horribly! We definitely need to fix that. Why didn't you report the issue with that right away?
Updated the IS to reflect the real problem.
A quick look at
\Drupal\Core\Plugin\DefaultPluginManager::findDefinitions()also shows that using an alter hook also won't be able to fix this problem. So, indeed, it seems we will need to move that filter and argument to a separate module (maybe using that opportunity to also make their names consistent). Which is really pretty ugly, and bad UX, but appears to be the only solution.As said, since Drupal requires the user module (and a lot of our code is using users), I don't think we need to do the same for users.
Comment #8
mkalkbrennerBecause I didn't notice it before. It doesn't happen until you're running on a case-sensitive file system.
Therefor I just saw it on travis.com and you faced it on drupal.org test bot.
The fact that it works on a case-insensitive file system is a currently existing core bug.
We should revert #2775437: Fix the tests and its corresponding issues in search_api_solr and facets, too.
Comment #9
borisson_So this?
Comment #10
borisson_Oops.
Comment #13
borisson_Comment #15
borisson_Comment #18
borisson_The test runs out of memory on php5.x, php7 passes. I don't understand this.
Comment #19
borisson_@andypost suggested a great solution to fix something similar in facets; see the latest patch in #2775963: FacetsSerializer views style plugin depends on optional rest module, a similar solution would mean no changes for facets to go back to green tests. That would be a great solution imho.
Much better than the solution in the previous patches I uploaded anyway.
Comment #20
andypostAlso I'd better filed new issue to reorganize folders for modules and test modules
Comment #21
borisson_Comment #22
borisson_@drunken monkey: if this patch applies and passes, and you agree with the solution, please credit @andypost as well. I wouldn't have figured this out without his example.
Comment #24
mkalkbrennerThe last patch is an interesting approach. But I wonder if there's any "officially" recommended pattern for the issue because there must be various modules affected by the same issue.
Comment #25
mpp commentedIsn't this actually a core issue? See https://www.drupal.org/node/2776235
Comment #26
drunken monkeySee my comment #7:
Unless I'm mistaken, moving the class to a sub-module with the proper dependency is really the only way to solve this problem.
Patch attached, based on #15 (or, rather, #13 plus the interdiff from #15 – you had unrelated changes in the patch file from #15). Locally, it passes, but I'm also using PHP 7. Not sure what to do if it keeps failing on PHP 5.
I only renamed the argument class to follow the name of the filter class. Also, I think
search_api_views_taxonomy, or at leastsearch_api_views_taxonomy, would be a better name for the new module.That doesn't seem to have anything to do with it.
Comment #27
drunken monkeyComment #29
borisson_That makes sense, The fails on php5 are still happening but it's green on php7, so I guess this is the correct way to resolve this.
Comment #30
drunken monkeyOK, thanks!
And any opinion regarding the name of the new module?
search_api_term,search_api_views_taxonomyorsearch_api_views_taxonomy?Comment #31
andypost+1 to
search_api_views_taxonomyComment #32
mpp commentedAny reason we're testing on D8.3? The tests succeed for D8.1, seems like there is an issue with 8.3.
Comment #33
mpp commentedThe default branch for testing should be set to 8.1, not 8.3. See https://www.drupal.org/node/2784849.
Comment #34
drunken monkeyRenamed the new module to
search_api_views_taxonomy. Also, remove all references to the two handlers from the Search API module into the new module (seems we kinda forget about that bit before).Still seems RTBC to me, any objections?
(Would be great to have tests for those handlers, too, but that probably shouldn't hold up this issue. We can create a followup for that.)
As said in the other issue, this is a known problem and nothing we can fix in the Search API.
Comment #36
borisson_I agree with the changes, but it seems that the testbot doesn't.
Comment #38
drunken monkeyThe test bot has been brought to reason, fortunately.
Since I'm reading an "RTBC" from your comment: committed.
Thanks again, everyone, for your work here!
Comment #39
borisson_Awesome! This should make the facets tests green as well again, checking that out later today. Thanks so much for your hard work here @drunken monkey!
Comment #40
mkalkbrennerI'll check and modify the solr tests now as well.
Comment #42
drunken monkeyIn case anyone reads closed issues: I'm proposing a way better solution in #2917399-10: Missing / broken handler when adding a filter for a field.