Problem/Motivation
When a deprecated setting has no replacement, Settings::get() currently triggers a deprecation warning on every call, even when the setting is not configured in settings.php.
This causes spurious deprecation warnings across unrelated test classes. For example, every kernel test that instantiates UpdateFetcher or SecurityAdvisoriesFetcher generates a deprecation warning for update_fetch_with_http_fallback (see related issue : #3591513: Deprecate the update_fetch_with_http_fallback setting), even though neither the module nor the site has that setting configured.
The deprecation warning for a setting with no replacement is only meaningful when the site actually has that setting configured in settings.php, since that is the only actionable signal for a site owner: "remove this setting from your settings.php". Triggering it unconditionally is misleading and pollutes test output.
Proposed resolution
Modify Settings::get() to only trigger the deprecation warning when at least one of the following conditions is true:
- The setting has a replacement key (calling code must be updated to use the new key), or
- The setting is actually present in storage (the site owner must remove it from
settings.php).
Settings with no replacement that are not configured should not trigger any warning.
Remaining tasks
- Patch
Settings::get() - Add tests covering the new behavior
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork drupal-3592037
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3592037-settingsget-should-not
changes, plain diff MR !15872
Comments
Comment #3
macsim commentedComment #4
macsim commentedComment #5
smustgrave commentedSo ran the test-only locally and testGetNoDeprecationWhenNotConfiguredAndNoReplacement still passes that expected? Shouldn't both tests fail?
Comment #6
macsim commentedThanks for having a look!
I think the confusion might come from which branch the tests were run against.
testGetNoDeprecationWhenNotConfiguredAndNoReplacementdoes callSettings::get()(viaassertNull()), and since it has no#[IgnoreDeprecations]attribute, any triggered deprecation would cause it to fail.So the expected behavior is:
Settings::get()unconditionally triggers the deprecation.Could you confirm whether you ran the tests on
mainor on the issue branch?Comment #7
smustgrave commentedSorry I got it twisted that one did fail without the fix. testGetDeprecationWhenConfiguredAndNoReplacement was the one that passes but I see now why
My mistake. This LGTM
Comment #9
alexpottFor the PHPCS changes see https://www.drupal.org/project/coder/issues/3226902
Comment #13
catchCommitted/pushed to main, 11.x and 11.4.x, thanks!
Comment #16
macsim commented#3591513: Deprecate the update_fetch_with_http_fallback setting is in a Needs review status because we don’t know if it’s still ok or too late for a 11.4 deprecation. Feel free to give your opinion :-)