Problem/Motivation
When updating on last dev, error occur:
Error: Call to a member function setNewPresent() on null in Drupa l\display_builder_entity_view\Entity\EntityViewDisplay->postSave() (line 18 2 of /checkout/web/modules/contrib/display_builder/modules/display_builder_entity_view/src/Entity/EntityViewDisplayTrait.php)
Steps to reproduce
Proposed resolution
Here is a patch proposition by @yannickoo
public function postSave(EntityStorageInterface $storage, $update = TRUE): void {
// Reset the state once you import a configuration.
- if ($this->isSyncing()) {
- $instance = $this->getInstance();
+ if ($this->isSyncing() && ($instance = $this->getInstance())) {
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
mogtofu33 commentedComment #4
pdureau commentedOK for me.
Comment #5
pdureau commentedComment #6
pdureau commentedComment #7
mogtofu33 commentedComment #9
pdureau commentedI see it was not merged yet. Maybe because of fails in phpunit. So back to "Needs work".
This fail was expected, and is related to changes in UI Patterns 2.0.16 released yesterday:
We just need to update the order of properties in the tests.
There are also 4 "Failed asserting that an array is empty." fails, because an empty array inside an empty array is not considered empty by PHP:
Investigating.
Comment #10
mogtofu33 commentedI checked to fix the tests, but so we have now this root array with 'node_id' but source_id = NULL.
Comment #11
pdureau commented3 commits pushed on the MR, I guess this ticket is on your side.
Are you sure those changes in EntityViewDisplayTrait, API controllers, Instance entity and SourceTree are needed just because we have updated UI Patterns from 2.0.15 to 2.0.16?
Comment #12
mogtofu33 commentedEntityViewDisplayTrait is the original bug fix.
There is some inconsistency changes unrelated, like save() usage. But mostly it's tests fix and workaround this source_id => NULL from ui_patterns.
But would be great to know if it's a problem from ui_patterns.
Seems like ui_patterns SourceValueItem inherit FieldItemBase inherit Map for function isEmpty() wich check null when we are empty array. Then FieldItemList::filterEmptyItems() could remove the phantom stuff as currently it didn't.
Comment #13
mogtofu33 commentedI removed the workaround and created an issue on ui_patterns https://www.drupal.org/project/ui_patterns/issues/3604317
Comment #14
pdureau commentedI was investigating that this afternoon.
Argument #1 ($source_id) must be of type string, null given, called in SourceTree.phpis caused by this (relevant) change in UI Patterns:Because we are losing the (maybe too) generous
MapItem::isEmpty()and relying on the more strict and convoluted
Map::isEmpty().So, with those 3 additional lines in UI Patterns + reordering the properties in
InstancePublishingTest::testRestore()(2 lines) must be enough to fix, without the risk of changing our tests, the delicate SourceTree or the publishing logic.I take the ticket back to finish the investigation and maybe to propose another MR (or two 😉).
Comment #15
pdureau commentedI don't understand when I am supposed to work on this ticket or not 😕 it is the second time today commits are pushed while the ticket is assigned to me.
Comment #17
pdureau commentedHere is my proposal: https://git.drupalcode.org/project/display_builder/-/merge_requests/296/...
UI Patterns 2.0.16 compatibility OK with only 2 lines changed in
InstancePublishingTest::testRestore()& 3 lines added in #3604317: SourceValueItem missing isEmpty() causes phantom null items to survive filterEmptyItems() [AI assisted] (see my comment).Without the risk of doing changes in the tests, the SourceTree, the controllers... parts of the codebase which are delicate and tricky.
What do you think?
Edit: I forgot to update composer.json
Comment #18
pdureau commentedI will add the composer.json and also
DisplayBuilderKernelTestBase::testGetParentId()from your MR because it add coverage without expecting a change of the existing logic 😉Comment #19
pdureau commentedDone.
Comment #20
mogtofu33 commentedSorry, seems we were fixing it in the same time. I set needs review not needs work on your side but probably too late, I was working on the train to fix quickly as it's blocking all our MR on DB.
Once the fix in ui patterns is merged and released we'll be able to merge on Display Builder.
Following this ui patterns bug, how could we improve the ui patterns release to avoid this kind of breaking changes?
Comment #21
pdureau commentedI would not say those changes are made UI Patterns side (it has been a long time we are not changing anything in SourceValueItem) and are unfortunately breaking Display Builder.
Instead, those changes are made specially for Display Builder, to unlock features here, but in a confusing way because we didn't anticipate everything and it is taking us 3 tries to get things right:
Comment #22
pdureau commentedGreat. Which MR?
Comment #23
mogtofu33 commentedWhen this is merge #3604317: SourceValueItem missing isEmpty() causes phantom null items to survive filterEmptyItems() [AI assisted] and perhaps we have a release of ui_patterns.
Comment #24
pdureau commentedI was asking about the MRs of the current ticket:
I am still afraid the first one is doing too much. For example, this change in
InstancePublishingTest:And this change in
InstanceTest:Looks like leftovers of a previous stage of the investigations Potentially useless and harmful now we have moved the focus to #3604317: SourceValueItem missing isEmpty() causes phantom null items to survive filterEmptyItems() [AI assisted].
It would be safer to focus on the change of the 2 lines in
InstancePublishingTest::testRestore(), without too much modifications unrelated to the ticket scope.Maybe it is just me freaking out, and I would be happy to be contradicted and reassured 🤗
Comment #25
mogtofu33 commentedUI Patterns patch is not yet there, let's have it as a patch to not be stuck.
Refactored the tests to make it more simple, and use the Drupal test runner for parallel execution.
I am confident on other fixes in the MR.