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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dalin’s picture

Status: Active » Needs review
FileSize
1 KB

Status: Needs review » Needs work

The last submitted patch, 1858318-devel-efq-debug-1.patch, failed testing.

moshe weitzman’s picture

Why would the final query not go through the existing query log? Not sure why this is needed.

dalin’s picture

Assigned: Unassigned » dalin

Let's say that you do something like this:

$q = new EntityFieldQuery;
$results = $q->entityCondition('entity_type', 'node');
   ...
   ->execute();
dpm($results);
// $results is empty but I have no idea why.  I wish I could just see the query that was sent to the DB.

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.

moshe weitzman’s picture

Status: Needs work » Postponed (maintainer needs more info)

Please reread my question regarding the existing query log.

dalin’s picture

By 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.

moshe weitzman’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

You can search for the function that issued the query

haggins’s picture

Status: Closed (works as designed) » Active

I 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.

moshe weitzman’s picture

Status: Active » Closed (won't fix)
haggins’s picture

I exposed a use case where your solution does not work. Now you close this issue without any comment. This is rude.

gamelodge’s picture

I 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!!

dalin’s picture

Assigned: dalin » Unassigned
slefevre1’s picture

I 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! :)

bcweaver’s picture

Status: Closed (won't fix) » Active

I 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:

  • Services request
  • AHAH request
  • Batch API

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 ')'.

ximo’s picture

Adding 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.

fuerst’s picture

I 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().

fuerst’s picture

BTW: Use nicedpq() instead of dpq() to get a nice formatted output, replaced placeholder and to avoid the dreadful Fatal error: Maximum function nesting level of '100' reached.

jonhattan’s picture

Status: Active » Needs work

Marked #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.

jonhattan’s picture

pcambra’s picture

I think we could consider including Nice DPQ as part of devel if everyone agrees?

salvis’s picture

Please start a new issue for discussing adding Nice DPQ.

pcambra’s picture

kenorb’s picture

kscheirer’s picture

https://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!

lex0r’s picture

Issue summary: View changes

@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.

kscheirer’s picture

Hmm, well it worked great 6 months ago :D

When did EFQ lose its __toString() function?

dalin’s picture

FileSize
665 bytes

Sounds 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).

joelpittet’s picture

Status: Needs work » Needs review
kenorb’s picture

I think 'debug' tag should be used, as it's cleaner than 'debug-in-progress'. Or just 'devel'.

dalin’s picture

FileSize
697 bytes

@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.

willzyx’s picture

Assigned: Unassigned » moshe weitzman
Status: Needs review » Reviewed & tested by the community

Looks RTBC to me.. invoking @moshe for his approval

moshe weitzman’s picture

Status: Reviewed & tested by the community » Needs work

The doxygen says to use tag 'debug' but the code never uses that tag.

dalin’s picture

Status: Needs work » Needs review

@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'.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

That makes sense. Looks good to me.

  • willzyx committed 9e4a40f on 7.x-1.x authored by dalin
    Issue #1858318 by dalin: Make debugging EFQ easier by implementing...
willzyx’s picture

Assigned: moshe weitzman » Unassigned
Status: Reviewed & tested by the community » Fixed

Committed/pushed to the 7.x version. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.