3

I have experienced a very strange behaviour of Drupal 7. I had Devel module activated, and a View which made the sql logs to disappear from screen. The view was used by views_get_view_result(). When I have changed the exact code to use views_embed_view(), with the same and exact rendering, the SQL logs started to appear again.

Is there some Drupal 7 expert (ninja level suspected) out there that can understand what could happen? The bug was consistent, it always happened in the same View config (I replicated different Views with different names and the behaviour always appeared at the same point).

The configuration that caused the problem was:

  • Field collection
  • View with field collection
  • Contextual filter (here it started to ignore sql log output)
  • Call to the function views_view_result. Even the call itself, without using the value, caused the problem.

Solution: Call views_view_embed() instead. No problem anymore. Same contextual filters, and blocks used. Exact configuration and exact output than views_view_result().

Note: I need an explanation of why this is happening, and a possible solution. The output of the SQL logging is not sent to the HTML source output of the page.

Code used. The commented lines do not work, and are substituted by the non-commented lines above them. The function is supossed to return an integer.

 function sacar_numero_productos($id_categorias, $marca){
     $marca = str_replace("/", "", $marca);
     $a = views_embed_view("numero_productos", "block_1", $id_categorias, $marca);
    // LINE BELOW DOES WORK BUT DESTROYS THE OUPUT OF SQL QUERIES
    //$a = views_get_view_result("numero_productos", "block_1", $id_categorias, $marca);

return (int)(trim(strip_tags($a)));

   // IF I USE views_get_view_result, this is the return value instead.
   /*if(isset($a[0]->field_data_field_id_unico_oem_field_id_unico_oem_value) && (int)$a[0]->field_data_field_id_unico_oem_field_id_unico_oem_value > 0){
       return (int)$a[0]->field_data_field_id_unico_oem_field_id_unico_oem_value;
    } // if*/
    return 0;
} // function
4
  • You need to be a bit more precise. I'm guessing you are talking about views_get_view_result not views_view_result. views_get_view_result isn't used anywhere so I'm guessing you have some custom code doing this. The SQL output you are referring to, is that what is possible to enable from devel module? Did you check that the markup is missing (that it's not a styling issue)?
    – googletorp
    Commented Nov 28, 2016 at 12:09
  • I use views_get_view_result (thanks for the correction), and it is working in the last D7 version. The output source is not delivered, it is not a problem of styles. And yes, the output sql is what is delivered when you check the "Display query log" option.
    – Cesar
    Commented Nov 28, 2016 at 12:30
  • Can you provide the exact code you wrote, both version which has issue and version which doesn't?
    – googletorp
    Commented Nov 28, 2016 at 14:34
  • I have added the code. The result of the view in the Views GUI is exactly the same, it is a text meaning a number. The difference in getting the code is because of the Drupal function called.
    – Cesar
    Commented Nov 28, 2016 at 16:24

2 Answers 2

4
+200

The short answer: Devel is not incompatible with Views.

The longer answer:

The difference between views_embed_view and views_get_view_result is essentially that views_embed_view renders the view while views_get_view_result only executes it. The code for the two processes are almost identical, but the difference is that views_embed_view does more as part of the render process. You can see the details in view::render.

The gist of it is that when embedding the view, you get views to do a lot more things, like initializing the theme, invoking more hooks.

Best guess for where your problem lies would be some other module integrating with views and/or devel or some other details you haven't written in your question.

The devel query log works by using the core database log, starting it with hook_boot and getting the info with a shutdown function. There are some scenarios where devel will be silent, fx when doing redirects. There is a good chance, that the issue is related to how devel figures out when to be silent or not. It's near impossible to figure out the exact cause without being able to debug your exact site and configuration as any module / configuration can be the cause to what you are seeing. If you want to investigate you should look into

  • devel_silent()
  • devel_shutdown()
  • devel_shutdown_real()
2

Sometimes query log arguments and explain functionality do not work on pages generated by a view because some elements returned by Database::getLog (used internally by devel) contain very complex objects in caller arguments; This causes silent failure in json_encode (used to serialize the query logs data) due 'Recursion detected' error, so no data is written to devel query log files nor shown on the screen.

The issue should be solved in SQL query log doesn't work on pages generated by a view. Try to use the latest devel -dev version and see if the issue still occurs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.