Problem/Motivation
Summary
(from #1054162-30: Taxonomy bundles not supported by EntityFieldQuery (followup))
@tim.plunkett has discovered that #1361232: Make the taxonomy entities classed objects causes a regression with taxonomy entity field queries such that they now cause warnings and notices. An automated test that exposes this bug is attached.
Details
- A basic EFQ using the taxonomy type seems to work, but causes multiple errors, beginning with
array_flip(): Can only flip STRING and INTEGER values!inDrupalDefaultEntityController->load(). See http://qa.drupal.org/pifr/test/262368 for details. - This bug did not exist prior to the taxonomy entity conversion. The automated test passes prior to that commit.
- This bug was introduced by the taxonomy entity conversion. The test fails when applied to that commit.
Steps to reproduce
-
git show 5a8e7bd(This is the commit from #1361232: Make the taxonomy entities classed objects.)
-
git checkout -b temp 5a8e7bd^(Check out the last commit before then.)
-
git apply --index taxonomy-efq-test-5a8e7bd-do-not-test.patch git commit -am "Taxonomy EFQ bug."(The current test patch does not apply to this commit, so I've attached a version to apply there for convenience.)
-
Run the Taxonomy EntityFieldQuery test. Test passes.
-
git rebase 5a8e7bd(Move the same test up on top of the taxonomy entity conversion commit.)
-
Run the Taxonomy EntityFieldQuery test. Test assertions pass, but there are lots of exceptions reported.
-
git rebase origin/8.x(Move the same test up on top of 8.x HEAD.)
-
Same result; lots of exceptions.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | drupal-1550454-18.patch | 2.57 KB | tim.plunkett |
| #18 | interdiff.txt | 586 bytes | tim.plunkett |
| #11 | drupal-1550454-11.patch | 2.57 KB | tim.plunkett |
| #10 | drupal-1550454-10.patch | 2.46 KB | tim.plunkett |
| taxonomy-efq-test-5a8e7bd-do-not-test.patch | 1.56 KB | xjm |
Comments
Comment #1
xjmSending to the bot.
Comment #2
xjmNote that, just to be sure, I tested with the fix from #1054162-23: Taxonomy bundles not supported by EntityFieldQuery (followup) and confirmed that it does not resolve this.
Comment #2.0
xjmUpdated issue summary.
Comment #3
xjmNote that I haven't debugged this yet other than to confirm the regression Tim found.
@Berdir also suggested that we should see if there are similar exceptions for users, comments, or nodes with EFQ.
Comment #4.0
(not verified) commentedUpdated issue summary.
Comment #5
berdirIs it possible that this is also related to the entity_load() rename. Something is passing invalid arguments to entity_load_multiple(). Try adding a "debug(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))" right before the test exception happens, that should lead you right to place where this is happening.
Comment #6
Anonymous (not verified) commentedso the flow before the asplode is:
call_user_func_array --> system_batch_page --> _batch_page --> _batch_do --> _batch_process --> call_user_func_array --> _simpletest_batch_operation --> DrupalTestCase::run --> TaxonomyEFQTestCase::testTaxonomyEFQ --> EntityFieldQuery::execute --> call_user_func --> EntityFieldQuery::propertyQuery --> EntityFieldQuery::finishQuery --> entity_create_stub_entity --> entity_create --> TaxonomyTermController::create --> taxonomy_vocabulary_load:
the key brokenosity seems to be that we pass this to TaxonomyTermController::create():
this is then passed to EntityDatabaseStorageController::create() --> TaxonomyTerm::__construct().
problem is that TaxonomyTerm just doesn't work without also passing in 'vid'. we don't validate that when creating the object, instead we just blow up somewhere down the road a bit.
not sure what the right fix is amongst all those chained calls, but hopefully this will help whoever does know.
Comment #7
xjm@Berdir, the patch fails on commit g5a8e7bd and passes before it, so it's definitely related to the entity conversion, because this is before the
entity_load()rename. I'll update the summary to make this clear.Comment #7.0
xjmUpdated issue summary.
Comment #8
xjmClarifying title (I hope).
Comment #8.0
xjmUpdated issue summary.
Comment #8.1
xjmUpdated issue summary.
Comment #8.2
xjmUpdated issue summary.
Comment #8.3
xjmUpdated issue summary.
Comment #8.4
xjmUpdated issue summary.
Comment #8.5
xjmUpdated issue summary.
Comment #8.6
xjmUpdated issue summary.
Comment #8.7
xjmUpdated issue summary.
Comment #9
tim.plunkettAn interesting note, if you debug($results); in the working state (before the entity conversion), the result is an array of stdClass objects with only tid set.
Currently in 8.x, EFQ still only returns the tid, but it now returns an array of TaxonomyTerm objects. And since it only passes in the tid to the constructor, vital things like vid and vocabulary_machine_name are set to NULL.
Comment #9.0
tim.plunkettUpdated issue summary.
Comment #10
tim.plunkettThere is NO WAY we should do this.
Just proving that it works.
Comment #11
tim.plunkettThis reverts entity_create_stub_entity to the D7 version of it, aka before #1184944: Make entities classed objects, introduce CRUD support.
Comment #12
tim.plunkettHm, this seems like it might even be the right fix.
For the entity types that have been converted (everything except file), EFQ gives completely different results than D7.
Given
Here is the result of D7:
And here is D8:
At least in D7 it was clear this was a stub entity. In D8 its not the case, because it's run through entity_create first. Not doing that and just having a stub entity be a stdClass actually seems more correct to me.
Comment #13
tim.plunkettThis should be asort(), I'll reroll after someone looks at this.
Comment #14
berdirLooking at the todo here, it looks like this function is supposed to be removed in favor of entity_create() once all classes have been commited and now it's just File that's missing.
So I'd argue that we should fix the usage of this funciton, not revert it.
Comment #15
tim.plunkettWell when I think about what a stub entity is, I don't think it SHOULD be run through entity_create.
The return value says "An entity object, initialized with the IDs provided."
Not "A classed entity object, initialized with the IDs provided and everything else set to NULL."
You have the entity_type and enough info to load the full entity yourself.
Comment #16
berdirOk, discussed this with timplunkett in IRC and we came to an agreement. To quote myself:
The entity stub follow-up is at #1551140: Remove stub entities, replace entity_create_stub_entity(), more detailed explanation of the idea can be found there.
I haven't found an issue for cleaning up the vocabulary_machine_name/vid mess, surprisingly. Does one exist?
Comment #17
sunLooks good to me. Thanks for debugging this!
And no, we need to create an issue for the vocabulary_machine_name/vid mess. (great simplification ahead)
Comment #18
tim.plunkettAs I mentioned in #13, that ksort should have been asort. Leaving at RTBC.
Comment #19
xjmKickass work! The whole stdClass thing is weird but I am down with handling it in #1551140: Remove stub entities, replace entity_create_stub_entity(). +1 on the RTBC.
Can we clarify what the "vocabulary machine name/vid mess" is? Does this mean getting bundles working with EFQ? (That would be #1054162: Taxonomy bundles not supported by EntityFieldQuery (followup).) Otherwise, all we have are these:
http://drupal.org/project/issues/search/drupal?text=machine+name&status%...
So if appropriate, could we get that followup filed with details of what should happen? Is it "use machine name everywhere in the API?" Also we should add said issue at #1347542: [META] Taxonomy API improvements. :)
Comment #20
berdir#1054162: Taxonomy bundles not supported by EntityFieldQuery (followup) is a backportable fix for EFQ. A prober solution would not require this fix in the first place. The current situation with vid/machine_name is the same as if the node_type table had an auto-increment key and nodes would reference that and not the machine_name. If we fix that then we can either revert that fix if it has been commited by then or move it down to 7.x.
Created an issue #1551774: Replace taxonomy_term_data.vid with vocabulary_machine_name
Comment #21
webchickI think this is the kind of patch I can commit to 8.x in order to fix brokenness, but the last couple of comments have me confused about whether this is actually RTBC.
Comment #22
berdir#18 is RTBC. the discussion in the last two comments is not about this patch but how to continue in follow-up issues.
Comment #23
catchFollow-ups look fine to me. Committed/pushed this one to 8.x.
Comment #24.0
(not verified) commentedUpdated issue summary.