I'm using the following code in my custom formatter:
$result = '';
foreach ($variables['#items'] as $delta => $item)
{
if ($item['access']) {
$nid = $item['nid'];
$url = url(drupal_get_path_alias('node/' . $nid), array('absolute' => TRUE));
$entity_type = 'node';
$bundle = 'page';
$nids = array($nid);
$field_values = db_select('field_revision_field_optional', 'f')
->fields('f', array('entity_id', 'field_optional_value'))
->condition('entity_type', $entity_type, '=')
->condition('bundle', $bundle, '=')
->condition('entity_id', $nids, 'IN')
->condition('deleted', 0, '=')
->execute()
->fetchAllKeyed();
$text = $field_values[$nid];
$result .= '<a href="' . $url . '">' . $text . '</a>, ';
}
}
return substr($result, 0, -2);
With having devel's logging mysql-queries enabled I get the following error (its number of duplicates depends on number of values printed by formatter):
Notice: Undefined index: args в функции DatabaseLog->findCaller() (строка 156 в файле /home/u9501/domains/progprofi.ru/includes/database/log.inc).
I don't know whose problem it is: mine, yours or devel module's?
Comment | File | Size | Author |
---|
Comments
Comment #1
Deciphered CreditAttribution: Deciphered commentedActually, it appears that the issue isn't the formatters, Custom Formatters or Devels fault. It looks to be an issue in Drupal itself.
The easiest way to reproduce the issue requires the Devel module:
db_select('node', 'n')->fields('n')->execute();
The issue is that there is no check if args is set on the next stack, it's just assumed it always is, but in the case of eval() it isn't.
Comment #2
Deciphered CreditAttribution: Deciphered as a volunteer commentedTested and issue does not seem to be present in Drupal 8.
Patch for Drupal 7 attached.
Comment #3
realityloopUsing the steps to reproduce in #1 I was able to confirm the issue, and the patch in #2 resolved it.
This patch is very straightforward and follows the same logic that is already used for other variables within this part of the code. RTBC
Comment #4
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedThe code in Drupal 8 looks extremely similar - are we really sure this doesn't need to be fixed there? (see Log::findCaller)
Not sure if a test makes sense here or not, but that would be one way to ensure it's fixed in Drupal 8 :)
Comment #6
daffie CreditAttribution: daffie commentedThe code test
db_select('node', 'n')->fields('n')->execute();
with logging enabled is not generating the error. Calling the method fields() with one parameter just get you all the fields from the node table.I agree with with David Rothstein that it should properly be fixed in Drupal 8. If someone else has an idea for a test, please say so!
Comment #8
Gribnif CreditAttribution: Gribnif commentedI can still duplicate this bug in D8. The easiest way to do so is to run this code within /devel/php:
Basically, it happens whenever a function that is part of an eval() runs a database query. The same thing can be triggered when an entity uses the PHP Code text formatter in one of its fields.
Attached is a patch that fixes the issue.
Comment #10
Jorrit CreditAttribution: Jorrit at nCode commentedThe line
$stack[$i] += ['file' => '?', 'line' => '?', 'args' => []];
can be reduced to just$stack[$i] += ['file' => '?', 'line' => '?'];
with this change.Comment #14
halthHi @Gribnif
Thanks for you notes and for the patch attached.
I should say though, that I couldn't reproduce the issue on a fresh D8 install (8.8.x) by following the steps proposed by you on #8.
Can you give it a try and double check that you can reproduce the issue under these circumstances on a fresh D8 install?
Comment #15
Gribnif CreditAttribution: Gribnif commentedI can no longer reproduce the problem, either. Given that it concerns the debug_backtrace() call, it could be that it only happens with certain versions of PHP.
Comment #16
halthCool. So how should we proceed with the issue? Do you think we should we close it? Does anyone in the comments have any thoughts on this?
I was facing this issue on an 8.7.x install while executing a query through the "Execute PHP" page, from devel_php.
Not sure if this is really a core issue, even though the fix proposed in the patches seem reasonable to me. That `isset()` call could potentially "close the door" for new trouble.
What do you guys think?
Comment #18
mondrakeSee #2867788-24: Log::findCaller fails to report the correct caller function with non-core drivers.
Comment #19
mondrakeThis change, below, in #2867788: Log::findCaller fails to report the correct caller function with non-core drivers. should have fixed the issued here, for D9 (and for D8 if the patch gets backported).
However, a test could be added to make sure we do not regress here. The test could be added to
Drupal\KernelTests\Core\Database\testContribDriverLog
, by adding another sample backtrace to theproviderContribDriverLog
that has noargs
key, and checking that the returned entry has an empty array for theargs
key.Comment #20
xjmSince we should fix this bug in D8 too, I'm filing it against 8.8.x (which is the current bugfix support branch). Patches can be tested against other branches as needed when they're uploaded.
The issue will be automatically updated to 8.9.x after the last 8.8.x bugfix release. Thanks!
Comment #24
DanielVezaNow that D8 is out of support and this is fixed for D9 I'm moving this back to the 7 queue.