Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
DefaultSingleLazyPluginCollection
should not be able to call createInstance()
with a NULL instance ID.
Proposed resolution
Check before instantiating.
Remaining tasks
review/commit
User interface changes
no
API changes
no
Data model changes
no
Comment | File | Size | Author |
---|---|---|---|
#58 | 2853234-58.patch | 5.71 KB | andypost |
| |||
#58 | interdiff.txt | 1014 bytes | andypost |
#56 | 2853234-56.patch | 5.7 KB | andypost |
#56 | interdiff.txt | 3.81 KB | andypost |
Comments
Comment #2
tim.plunkettComment #3
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedRan into this while working on #2831274: Bring Media entity module to core as Media module (see my comment #305 on that issue for more info).
Patch looks good to me, but would be great if someone that is more familiar with the plugin system would check it too.
Comment #5
dawehnerThis makes sense for me.
Comment #6
effulgentsia CreditAttribution: effulgentsia at Acquia commentedIn
DefaultSingleLazyPluginCollection
, the PHPDoc for$instanceId;
is@var string
, and for the$instance_id
parameter in__construct()
is@param string $instance_id
. So I think if we want to allow for NULL, we should update those docs. Alternatively, maybe we should throw an exception in__construct()
and/oraddInstanceId()
if it's NULL?Comment #7
tim.plunkettOkay, rethinking this in light of:
What we'd want to happen if we were writing this as a new API
What needs to be done to preserve full BC
Once the object is constructed, internal code should be able to rely on $this->instanceId being a string as it is supposed to be.
So I don't think we should add any type checking on the internal property.
Ideally we would trigger an error for anyone passing in NULL, but that's blocked on #2575081: [policy, no patch] Use E_USER_DEPRECATED in Drupal 8 minor releases
I expanded the test coverage, the newly added case would have also failed in 8.2.x and before, and is unrelated to the recent other changes.
Comment #8
joachim CreditAttribution: joachim commentedLooks good to me, except for:
This doesn't look like a related change.
Comment #9
tim.plunkettBefore we always instantiated $this->configuration in the constructor via the addInstanceId call.
Now since that won't always be called, we need to ensure it is an array. Also, since it's not documented as
array|null
, this is correct anyway.Comment #10
joachim CreditAttribution: joachim commentedThanks for the explanation!
In which case, I'd say this is ready.
Comment #11
alexpottI think given that we're planning to put a deprecation notice here we should consider doing that in this issue. Because with this change now addInstance is not called on every instantiation. In core this doesn't cause a problem because we only we really on it to initialise $configuration but the same might not be true in contrib. Without the @trigger_error they might not know that something has changed. Well, even with this is possible but at least we're being helpful.
Also since this is a change in behaviour in a class that is an extension point we should have a CR.
Comment #12
tim.plunkettYeah, #2575081: [policy, no patch] Use E_USER_DEPRECATED in Drupal 8 minor releases wasn't done at the time. We can do this now!
Good catch.
Comment #16
tim.plunkettComment #18
tim.plunkettComment #20
tim.plunkettComment #27
smustgrave CreditAttribution: smustgrave at Mobomo commentedRerolled and updated deprecation message.
Comment #28
smustgrave CreditAttribution: smustgrave at Mobomo commentedIgnored #27
Comment #29
smustgrave CreditAttribution: smustgrave at Mobomo commentedAlso took a shot at the change record. So removing that tag.
Comment #30
longwaveThanks for reviving this one.
Deprecation messages need to match the standard format: "... is deprecated in drupal:10.1.0 and is removed from drupal:11.1.0. See https://www.drupal.org/node/3302915"
Comment #31
smustgrave CreditAttribution: smustgrave at Mobomo commentedUpdated based on #30
Comment #32
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #33
andypostit should be `drupal:10.1.0` and `drupal:11.0.0`
wondered why sniffers skipped it
unrelated change, please remove
Comment #34
smustgrave CreditAttribution: smustgrave at Mobomo commentedUpdated based on feedback in #33
Comment #35
longwave> wondered why sniffers skipped it
Because of sprintf() call - only exact strings are checked, too many false positives with dynamic strings.
Comment #36
borisson_The last change contains a lot of theme related things as well, is that on purpose? Change request looks good.
Comment #37
longwaveYeah the theme related changes look like they come from a Bartik removal patch, out of scope here. NW to undo those.
Comment #38
smustgrave CreditAttribution: smustgrave at Mobomo commentedSorry about that.
Comment #39
andypostplease replace "sprintf" to allow sniffers to catch format
Comment #40
joachim CreditAttribution: joachim commentedDo we need to do a trigger_error() here, or could we throw an exception?
IIRC, at the moment, if $instance_id is NULL it crashes.
So if we throw an exception here, we're changing people's code from one crash to another.
Comment #41
smustgrave CreditAttribution: smustgrave at Mobomo commentedUpdated patch based on #39
Comment #42
andypost++ to #40, changed wording and using exactly a tested class
Comment #43
andypostFiled child to remove deprecation in 11.x #3303176: DefaultSingleLazyPluginCollection throw exception to instantiate a NULL instance ID
Comment #44
andypostwould be great to get a real example (maybe contrib) to prove it, otherwise follow-up is #2579743: Config entities implementing EntityWithPluginCollectionInterface should ask the plugins to react when their dependencies are removed
Comment #45
joachim CreditAttribution: joachim commentedI don't about contrib, but I saw this in a project last week where a mistake in config caused DefaultSingleLazyPluginCollectionTest to be used with a NULL.
To reproduce in a test, in DefaultSingleLazyPluginCollectionTest::setupPluginCollection(), just add:
run the test and it fails with:
The line of the test which makes it fail is this in the anonymous class:
Comment #47
andypostas bug
Comment #48
smustgrave CreditAttribution: smustgrave at Mobomo commentedChange record is simple and makes sense.
Code has coverage.
Think this is good.
Comment #49
catchA bit nitpicky, but it won't be removed in Drupal 11, it's either going to be a type error if we explicitly type hint with string, or it'll throw an exception. Can we maybe say 'and must be a string in Drupal 11' instead?
Comment #50
Rishabh Vishwakarma CreditAttribution: Rishabh Vishwakarma at OpenSense Labs for DrupalFit commentedChanged according to the suggestion given in #49
Comment #51
Rishabh Vishwakarma CreditAttribution: Rishabh Vishwakarma at OpenSense Labs for DrupalFit commentedComment #52
Rishabh Vishwakarma CreditAttribution: Rishabh Vishwakarma at OpenSense Labs for DrupalFit commentedFixed PHP CBF errors from the earlier patch.
Comment #53
Rishabh Vishwakarma CreditAttribution: Rishabh Vishwakarma at OpenSense Labs for DrupalFit commentedFixed PHP CBF errors from the earlier patch.
Comment #54
smustgrave CreditAttribution: smustgrave at Mobomo commentedComment #55
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedTrying to Fix CCF errors.
Comment #56
andypostclean-up unrelated changes
Comment #58
andypostFix remaining message
Comment #59
smustgrave CreditAttribution: smustgrave at Mobomo commentedThink I'm able to review this as the patch has gone through several changes since I last worked on it 7 months ago.
Deprecation looks good, with change record
Tests look good and fail as expected without the fix.
Think this is good.
Comment #61
Wim LeersThis is still a problem.
Also, I just ran into a sibling issue: #3404023: DefaultSingleLazyPluginCollection::setConfiguration() accepts NULL but ConfigurableInterface::setConfiguration() does not.