Closed (fixed)
Project:
Rules
Version:
8.x-3.x-dev
Component:
Rules Core
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
20 Sep 2020 at 14:08 UTC
Updated:
22 Jul 2023 at 07:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
tr commentedThe strings above all come from our debug logging code.
I looked at this a bit and my impression is that this is a false positive caused by the difference between PSR-3 logging used by Symfony and Drupal logging. The former uses different placeholders and has different parameters, and Drupal core performs some gymnastics to bend its logging into the shape required for Symfony.
For example, the Symfony
log($level, $message, array $context = [])requires that $message is a string with PSR-3 placeholders, and $context is an array of placeholder replacements and other things. While Drupal logging (e.g. the messenger service) requires a message string to be either a plain string or aFormattableMarkupobject created byt($message, array $placehoders), but specifically there is no separate argument for placeholders.It's those "other things" in $context that are causing a problem - they are not being passed as placeholders, but as additional data needed by the logger at a different point in the code. Thus they don't have prefixes like placeholders do, and they shouldn't need prefixes. It seems to me that the deprecation notice is being a little too aggressive when checking prefixes, because it's assuming everything in $context is a placeholder when that's not true.
Drupal does have a compatibility layer, which we use already. See for example this code in RulesLog:
There may be a workaround to avoid this deprecation notice by artificially renaming some of the keys in the $context array so that they look like placeholder keys, but that's not something I'm interested in investigating right now.
Comment #3
tr commentedFrom https://api.drupal.org/api/drupal/vendor%21psr%21log%21Psr%21Log%21Logge...
So in this case, the Symfony specification clearly states that $context is not used just for Drupal placeholders, meaning the keys do not have to conform to Drupal placeholder key names with prefix.
And specifically in some cases you MUST use a key named "exception", which would also trigger the above deprecation notice.
This strengthens my initial impression that this deprecation is a false positive in our case, caused by Drupal core being too aggressive at identifying what is a placeholder. So if I were going to work on this (which I'm not, at the moment), the way I would approach it is to investigate that core Drupal deprecation notice with the intention of rolling a patch for core to remove the assumption about the contents of the $context array.
Comment #4
jonathan1055 commentedI have created a core issue #3173103: False positives when identifying what is a placeholder, for deprecation error
Comment #5
tr commentedPostponed, waiting for resolution of #3173103: False positives when identifying what is a placeholder, for deprecation error
Comment #6
jonathan1055 commentedChanged parent to new meta issue #3257972: [meta] Rules deprecated code D9 -> D10
Comment #7
tr commentedComment #8
tr commentedOpening up again because in Drupal 10 this issue is the cause of our only test failures.
Comment #9
tr commentedTrying something ...
Comment #10
tr commentedWell that's embarrassing. Here's a corrected patch.
Comment #11
tr commentedThe tests got further, but identified another place that needs to be modified. If I get this working I'll refactor the code to make it nicer - this patch is just trying a theory.
Comment #12
tr commentedThe code in this patch is optimized and documented.
Comment #13
tr commentedComment #14
joseph.olstadComment #16
tr commentedCommitted.