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

Command icon 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:

Comments

mogtofu33 created an issue. See original summary.

mogtofu33’s picture

Assigned: Unassigned » pdureau

pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs review » Reviewed & tested by the community

OK for me.

pdureau’s picture

Title: Update error » Skip config import if no instance entity
pdureau’s picture

mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

pdureau’s picture

Assigned: Unassigned » pdureau
Status: Fixed » Needs work

I 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:

[
     0 => Array &1 [
+        'node_id' => '1',
         'source_id' => 'component',
         'source' => Array &2 [],
         'third_party_settings' => Array &3 [],
-        'node_id' => '1',
     ],
 ]

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:

(
    [0] => Array (
            [node_id] => 
            [source_id] => 
            [source] => Array()
            [third_party_settings] => Array ()
        )
)

Investigating.

mogtofu33’s picture

I checked to fix the tests, but so we have now this root array with 'node_id' but source_id = NULL.

pdureau’s picture

Assigned: pdureau » mogtofu33

3 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?

mogtofu33’s picture

Assigned: mogtofu33 » pdureau
Status: Needs work » Needs review

EntityViewDisplayTrait 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.

mogtofu33’s picture

pdureau’s picture

Status: Needs review » Needs work
But would be great to know if it's a problem from ui_patterns.

I was investigating that this afternoon. Argument #1 ($source_id) must be of type string, null given, called in SourceTree.php is caused by this (relevant) change in UI Patterns:

-class SourceValueItem extends MapItem {
+class SourceValueItem extends FieldItemBase {

Because we are losing the (maybe too) generous MapItem::isEmpty()

  public function isEmpty() {
    return empty($this->values);
  }

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 😉).

pdureau’s picture

I 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.

pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs work » Needs review

Here 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

pdureau’s picture

Assigned: mogtofu33 » pdureau
Status: Needs review » Needs work

I will add the composer.json and also DisplayBuilderKernelTestBase::testGetParentId() from your MR because it add coverage without expecting a change of the existing logic 😉

pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs work » Needs review

Done.

mogtofu33’s picture

Status: Needs review » Patch (to be ported)

I 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.

Sorry, 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?

pdureau’s picture

Following this ui patterns bug, how could we improve the ui patterns release to avoid this kind of breaking changes?

I 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:

pdureau’s picture

Once the fix in ui patterns is merged and released we'll be able to merge on Display Builder.

Great. Which MR?

mogtofu33’s picture

pdureau’s picture

Great. Which MR?

When 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.

I was asking about the MRs of the current ticket:

  • the initial #294 MR
  • the alternative, smaller, #296 MR

I am still afraid the first one is doing too much. For example, this change in InstancePublishingTest:

-    $instance->setNewPresent($testData, 'Modified state');
-    self::assertSame($testData, $instance->getCurrentState());
+    $instance->setNewPresent([$testData], 'Modified state');
+    self::assertSame($testData, $instance->getCurrentState()[0]);

And this change in InstanceTest:

-    self::assertEmpty($instance->getCurrentState());
+    $node = $instance->getNode($node_id);
+   self::assertEmpty($node);

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 🤗

mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Patch (to be ported) » Fixed

UI 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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • mogtofu33 committed fab0ca5b on 1.0.x
    fix: #3603094 Skip config import if no instance entity
    
    By: mogtofu33
    By...