Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Debugging EntityFieldQuery is very difficult and requires going through several hooks just to see what query is being sent to the DB. We can make this process much smoother. Patch forthcoming.
Comment | File | Size | Author |
---|---|---|---|
#30 | 1858318-devel-efq-debug-30.patch | 697 bytes | dalin |
Comments
Comment #1
dalinComment #3
moshe weitzman CreditAttribution: moshe weitzman commentedWhy would the final query not go through the existing query log? Not sure why this is needed.
Comment #4
dalinLet's say that you do something like this:
This seems to be a fairly common problem that I have with EFQ. There is no way to get that query string out of EFQ
dpm((string) $q);
or anything similar don't work. The only way to get that string is to add a tag and implement hook_query_alter(). That's a lot of hoops to go through.Will re-roll a patch that actually applies to HEAD.
Comment #5
moshe weitzman CreditAttribution: moshe weitzman commentedPlease reread my question regarding the existing query log.
Comment #6
dalinBy existing query log you mean the long list that devel prints at the bottom of the screen?
Yes the query would show up there, but it would be much easier to just see the one query rather than scroll through the possibly > 100 other queries to find the one you need.
Comment #7
moshe weitzman CreditAttribution: moshe weitzman commentedYou can search for the function that issued the query
Comment #8
haggins CreditAttribution: haggins commentedI try to debug a EFQ that is used in a services callback remotely. So there's no way to scroll through the query list since no page is ever shown.
Comment #9
moshe weitzman CreditAttribution: moshe weitzman commentedComment #10
haggins CreditAttribution: haggins commentedI exposed a use case where your solution does not work. Now you close this issue without any comment. This is rude.
Comment #11
gamelodge CreditAttribution: gamelodge commentedI am having the same issue trying to debug queries that are being used as part of a service.
Although current solutions are available being able to target a single query by simply adding a debug tag that is baked in sounds like a great idea!!
Comment #12
dalinComment #13
slefevre1 CreditAttribution: slefevre1 commentedI am trying to run an entity field query in a feeds hook. Since feeds runs in a batch I can't see the output of devel's query log. Being able to see the query would have probably saved me a day's worth of futzing around.
Please don't close this for lack of imagination! :)
Comment #14
bcweaver CreditAttribution: bcweaver commentedI have also had to debug EFQ's in situations where they do not show up in devel's query log.. EFQs that are executed via:
I'm sure there are more instances where they will not be shown in devel's query log. What I have been doing is adding a tag to the EFQ, then implementing hook_query_alter() to check for that tag, and in that case, convert the query to string (which works because it's no longer an EFQ query but a regular DAPI object) and then append it to a file using file_put_contents() and using tail -f on that file to see the query.
I'm with #11 and #13 here -- this is a huge number of hoops to jump through just to figure out what the SQL looks like when you're getting a MySQL error saying syntax error at line one near ')'.
Comment #15
ximo CreditAttribution: ximo commentedAdding my voice to this issue, #14 explained it well.
Maybe this is more of a feature request for core's EFQ, but it would be great if Devel could fill that void for D7.
Comment #16
fuerst CreditAttribution: fuerst commentedI think the code from #1 belongs to your own custom module(s). It depends on a special configuration inside your code rather than providing an undependent function call like
dpq()
.Comment #17
fuerst CreditAttribution: fuerst commentedBTW: Use
nicedpq()
instead ofdpq()
to get a nice formatted output, replaced placeholder and to avoid the dreadful Fatal error: Maximum function nesting level of '100' reached.Comment #18
jonhattanMarked #1454142: Make dpq() function dump query of type EntityFieldQuery as duplicate of this.
dpq() returns a value. Extending it as proposed here is not adecuate, there's no way to return anything.
So, a separate function may be needed to print an eqf. Call it dpq_efq(), dpefq() or whatever. Also, implementing hook_query_TAG_alter() instead of hook_query_alter() seems appropiate.
Comment #19
jonhattanFYI #2078425: Add support for EFQ and be even nicer
Comment #20
pcambraI think we could consider including Nice DPQ as part of devel if everyone agrees?
Comment #21
salvisPlease start a new issue for discussing adding Nice DPQ.
Comment #22
pcambra#2088593: Add nicedpq() into Devel
Comment #23
kenorb CreditAttribution: kenorb commentedDuplicated: #2093117: Add debug tag to debug EntityFieldQuery queries
Comment #24
kscheirerhttps://drupal.org/project/nicedpq now supports easy debugging of EFQ's. Use 7.x-1.x-dev until a 1.1 is released. It uses the same trick as above, but wraps it up nicely. Thanks jonhattan!
Comment #25
lex0r CreditAttribution: lex0r commented@kscheirer, you are wrong:
Fatal error: Call to undefined method EntityFieldQuery::__toString() in /var/www/developer_drupal7/modules/nicedpq/nicedpq.module on line 17
It still relies on __toString that is not supported. I used dev snapshots for both devel and nicedpq.
Comment #26
kscheirerHmm, well it worked great 6 months ago :D
When did EFQ lose its __toString() function?
Comment #27
dalinSounds like the maintainers of Devel are not interesting in adding this. However the approach that NiceDPQ uses appears to be broken. So here's an updated patch (that is also more simple).
Comment #28
joelpittetComment #29
kenorb CreditAttribution: kenorb commentedI think 'debug' tag should be used, as it's cleaner than 'debug-in-progress'. Or just 'devel'.
Comment #30
dalin@kenorb, take another read through the patch. The tag to use is 'debug'. 'debug-in-progress' is just a semaphore.
Actually, here's a new patch to use the word 'semaphore' which is probably more clear.
Comment #31
willzyx CreditAttribution: willzyx commentedLooks RTBC to me.. invoking @moshe for his approval
Comment #32
moshe weitzman CreditAttribution: moshe weitzman commentedThe doxygen says to use tag 'debug' but the code never uses that tag.
Comment #33
dalin@moshe
This is an implementation of
hook_query_TAG_alter()
called
devel_query_debug_alter()
so we are only altering queries with the tag 'debug'.
Comment #34
moshe weitzman CreditAttribution: moshe weitzman commentedThat makes sense. Looks good to me.
Comment #36
willzyx CreditAttribution: willzyx commentedCommitted/pushed to the 7.x version. Thanks!