Postponed on #2283977: Create a new ConfigEntity type for storing bundle-specific customizations of base fields, which is introducing the BaseFieldOverride class described in this issue.

Problem/Motivation

  • When a new 'base_field_override' config entity is created, BaseFieldOverride::preSave() calls the target entity type's storage handler's onFieldDefinitionUpdate() method, passing it the base field definition as the "previous" definition. And similarly, when the override config entity is deleted, BaseFieldOverride::postDelete() calls onFieldDefinitionUpdate, passing it the base field definition as the "new" definition.
  • However, if it happens that a base_field_override config entity is being added to or deleted from a site that also implements an override via ContentEntityInterface::bundleFieldDefinitions(), then the above behavior is incorrect, since the previous definition prior to base_field_override insertion and the new definition after base_field_override deletion is the one returned by ContentEntityInterface::bundleFieldDefinitions(), rather than the base definition.
  • The above might be an extreme edge case, because using ContentEntityInterface::bundleFieldDefinitions() rather than config to override base field definition is specifically intended for when you need you content entity type completely decoupled from config, in which case there shouldn't be code adding and removing base_field_override config entities for it.
  • Also, it's not really clear what FieldableEntityStorageDefinitionInterface::onFieldDefinitionUpdate() is even for. The only implementation of it in HEAD is a completely empty function, even after #1498720: [meta] Make the entity storage system handle changes in the entity and field schema definitions. Perhaps we should consider removing it? Do storage handlers need to be notified of non-storage-related changes to field definitions?

Proposed resolution

Discuss the above and figure out what to do.

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#71 2321071-71.patch5.49 KBJelle_S
#47 fix_moderation_state_bfo_dependencies-2321071-47-do-not-test.patch3.09 KBherved
#39 2321071-39.patch5.21 KBDuaelFr
#39 interdiff.2321071.37.39.txt1.37 KBDuaelFr
#37 2321071-37.patch5.09 KBshubham.prakash
#28 config_error-2321071-28.patch6.24 KBclairedesbois@gmail.com
#25 2321071-25.patch5.22 KBmmrares
#25 interdiff-2321071-24-25.txt950 bytesmmrares
#24 interdiff-2321071-22-24.txt2.44 KByogeshmpawar
#24 2321071-24.patch4.18 KByogeshmpawar
#22 interdiff-2321071-18.patch2.48 KBguedressel
#22 2321071-baseFieldOverride-fails-22.patch4.18 KBguedressel
#21 interdiff-2321071-18.patch2.49 KBguedressel
#21 2321071-baseFieldOverride-fails-21.patch4.18 KBguedressel
#18 interdiff-2321071-17-18.txt1.31 KBdagmar
#18 2321071-baseFieldOverride-fails-18.patch1.98 KBdagmar
#17 2321071-baseFieldOverride-fails-17.patch1.97 KBdagmar
#14 2321071-baseFieldOverride-fails-14.patch1.93 KBkoppie
#13 2321071-baseFieldOverride-fails-13.patch1 KBkoppie
#10 2321071-baseFieldOverride-fails-10.patch817 bytesguedressel
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

Is there really an issue here ?

I mean, until some code decides to create a BFO for a base field, the definition that EM::getFieldDefinitions() hands out is the one that comes out of ET::bundleFieldDefinitions() (if present) or ET::baseFieldDefinitions().

Then, some code creates a BFO for that field, and saves it. It does so by doing :
EM::getFieldDefinitions($entity_type, $bundle)['field_foo']->getConfig($bundle);

This means that the BFO starts out with the values from ET::bundleFieldDefinitions(), as it should ?

mgifford’s picture

Status: Postponed » Active

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

guedressel’s picture

It's not the first time that we run into this issue while doing a config-import. This time after module upgrades - last times I'm can't remember the exact situation but might also been after some upgrade.

This is our exception breaking the import (Drupal 8.6.3):

TypeError: Argument 2 passed to Drupal\Core\Entity\ContentEntityStorageBase::onFieldDefinitionUpdate() must implement interface Drupal\Core\Field\FieldDefinitionInterface, null given, called in /drupal/web/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php on line 207 in Drupal\Core\Entity\ContentEntityStorageBase->onFieldDefinitionUpdate() (line 424 of /drupal/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php).

This block in web/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php is causing "the null":

    [...]
    if ($this->isNew()) {
      // @todo This assumes that the previous definition isn't some
      //   non-config-based override, but that might not be the case:
      //   https://www.drupal.org/node/2321071.
      $previous_definition = $this->getBaseFieldDefinition();
    }
    [...]

Here is a `var_export` dump of the BaseFieldOverride instance in question: https://0bin.net/paste/Z+rIGISbx1feTqCF#ms1LBhcaExJbNWOY5enxkfnunkJUtH1I...

:-(

guedressel’s picture

Is this happening because during config-import the baseFieldDefinition is not in place when the baseFieldOverride gets imported? Hence this is very specific to the config-import situation?

For now - since we need to roll out into production - we just skip the field definition update event trigger in this edge case. Especially since we have not found one single implementation of a field definition update handler:
https://api.drupal.org/api/drupal/8.6.x/search/onFieldDefinitionUpdate
(also none in all the module we have in use for this project)

guedressel’s picture

Found a version conflict in our config schemes!
That's why we came into this use-case.

So we fixed our project config-import by sanitizing our config YMLs.

Please don't follow my thoughts in #9 and #10 - they were not leading into the right corner

akalam’s picture

Having the same issue on config import during site install throw existing site configuration.
Can you guedressel please provide more information on how to sanitize the config yaml's?
Thanks in advance.

koppie’s picture

@akalam: For me, "sanitize" meant "delete the stored config files." I deleted all the files that ended in `scheduled_state` or `scheduled_date`.

I applied the patch in #10 and it helped, but it revealed another error, even after I sanitized the config (see above). Here's a new patch for postDelete() in the same file. I'm not sure if this patch should replace the one from #10, or supplement it. I'm going to try using both.

koppie’s picture

Unfortunately my last patch didn't fix the problem; undefined fields are causing problems in preSave(), postDelete(), and getBaseFieldDefinition(). Here's a new patch that combines all three fixes (two old, one new) into a single patch.

Leksat’s picture

Just FYI, I met the following error when uninstalled the content_moderation module.

TypeError: Argument 2 passed to Drupal\Core\Entity\ContentEntityStorageBase::onFieldDefinitionUpdate() must implement interface Drupal\Core\Field\FieldDefinitionInterface, null given

During module uninstall, the base field override config was not removed for the moderation_state field. E.g. config/sync/core.base_field_override.node.page.moderation_state.yml

This had no effect on the existing environments. But the new site installation (using Drush 9 site-install with existing config) was failing with the mentioned error.

The fix was to remove the base field override files manually from the exported config.

(Unfortunately, I have no time to dig this case dipper)

Lendude’s picture

Status: Active » Needs work
Issue tags: +Needs tests

Ran into this problem when doing config import when deleting X Paragraph types and all the fields on those paragraph types.

Seems that the bit 'Inform the system that the field definition is being updated back to its non-overridden status' runs into trouble if the system no longer contains the field it is trying to update.

Patch fixed the problem (thanks!) but it does seem to me that this fix might just be hiding an upstream error.

Also, this needs tests.

dagmar’s picture

Version: 8.6.x-dev » 8.8.x-dev
Status: Needs work » Needs review
FileSize
1.97 KB

Re-rolled for 8.8.x. This didn't apply anymore.

dagmar’s picture

guedressel’s picture

Today I hit this issue again.
Just for the record: The exported configuration of our project was not importable for me after a team mate did some module upgrades. Removing the the core.base_file_override.[entity-type].[entity-bundle].* configs fixed the config import process for us (as it did when I posted #11)

I'm still not sure why this issue arises in the first place. Is it either because during the module upgrade no clean config export was committed into the project git repos or because the config discrepancies only show up if you do a config import on a different instance (read: computer) as the original upgrade ran. Or maybe it's something totally different...

¯\_(ツ)_/¯

guedressel’s picture

Another day, same issue: This thing keeps annoying us.

Our newest finding is: BaseFieldOverride configurations do not get deleted when their base fields vanish.
In our current project we modified the Content Moderation settings what resulted in removal of the "moderation_state" field from various entity definitions (media and node bundles). But their core.base_file_override.[entity-type].[entity-bundle].* configurations stayed in the system.

Their config dependencies declare only the entity bundles, not the entity bundle's base fields it overrides. For example: core.base_file_override.node.page.moderation_state declares core.base_file_override.node.page as config dependency, nothing else.

What helped us today was again deleting obsolete configuration yaml files manually....

guedressel’s picture

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
FileSize
4.18 KB
2.44 KB

Resolved some coding standard issues & added an interdiff .

mmrares’s picture

I found a case when the FieldConfigBase::postSave was triggered and here, the BaseFieldOverride::getFieldStorageDefinition is called which returns NULL. So, I added a check in FieldConfigBase::postSave to check for this.

Renrhaf’s picture

We hit the following error when uninstalled the metatag module.

TypeError: Argument 2 passed to Drupal\Core\Entity\ContentEntityStorageBase::onFieldDefinitionUpdate() must implement interface Drupal\Core\Field\FieldDefinitionInterface, null given

During module uninstall, the base field override config was not removed for the metatag field. E.g. config/sync/core.base_field_override.node.page.metatag.yml

The fix was to remove the base field override files manually from the exported config.

Renrhaf’s picture

clairedesbois@gmail.com’s picture

Gold’s picture

Status: Needs review » Reviewed & tested by the community

We just had this issue on a local project. Our edge case was enabling translations and exporting the config for the subset of translateable fields set at admin/config/regional/content-language.

The patch at #25 worked resolved the issue for us.

I'm not sure how RTBC works with patches for multiple versions on the same issue but with that patch being for 8.8.x and the issue being for the same version I'm assuming it's okay to RTBC.

hchonov’s picture

Status: Reviewed & tested by the community » Needs work

Re #16:

Ran into this problem when doing config import when deleting X Paragraph types and all the fields on those paragraph types.

I am sorry, but I couldn't parse that sentence :). But it might not be important => see the next quotation.

Seems that the bit 'Inform the system that the field definition is being updated back to its non-overridden status' runs into trouble if the system no longer contains the field it is trying to update.

In order for this not to happen the override should be deleted when the field it overrides is deleted. We have an issue for that - #3043741: Delete base field overrides when removing entity fields they override..

Re #20, #21, #22

Our newest finding is: BaseFieldOverride configurations do not get deleted when their base fields vanish.

Handle empty return value of getBaseFieldDefinition() in other methods

So this is the reason for all the changes in the patch, where it is first checked whether the base field definition exists? Please let's revert them because #3043741: Delete base field overrides when removing entity fields they override. should prevent this from happening.

+++ b/core/lib/Drupal/Core/Field/FieldConfigBase.php
@@ -283,12 +283,18 @@ public function postCreate(EntityStorageInterface $storage) {
-    $this->entityManager()->clearCachedFieldDefinitions();
+    \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
...
-    if ($this->entityManager()->hasHandler($entity_type, 'view_builder')) {
-      $this->entityManager()->getViewBuilder($entity_type)->resetCache();
+    if ($this->entityTypeManager()->hasHandler($entity_type, 'view_builder')) {
+      $this->entityTypeManager()->getViewBuilder($entity_type)->resetCache();
+      if ($field_storage_definition = $this->getFieldStorageDefinition()) {
+        $entity_type = $field_storage_definition->getTargetEntityTypeId();
+        if ($this->entityTypeManager()->hasHandler($entity_type, 'view_builder')) {
+          $this->entityTypeManager()->getViewBuilder($entity_type)->resetCache();
+        }
+      }

These changes seem also unneeded.

+++ b/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php
@@ -163,8 +170,10 @@ public function getUniqueIdentifier() {
-      $fields = $this->entityManager()->getBaseFieldDefinitions($this->entity_type);
...
+      $fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($this->entity_type);
+      if (!empty($fields[$this->getName()])) {
+        $this->baseFieldDefinition = $fields[$this->getName()];
+      }

I guess this should be the main change? However you don't retrieve the bundle field overrides here. For that we'll need something similar to \Drupal\Core\Entity\EntityFieldManager::buildBundleFieldDefinitions(), which doesn't load the base field overrides.

We also still need a test.

hchonov’s picture

Please give credit to @effulgentsia for the amazing issue summary.

guedressel’s picture

@hchonov thank you for your insightful review.
Pointing to #3043741: Delete base field overrides when removing entity fields they override. is the crucial piece of information in it for me.

When I find time I'll revise my patch but I guess it's actually useless since I always just responded to symptoms and never had a clue how to approach the actual issue as discussed in #3043741: Delete base field overrides when removing entity fields they override..

That being said I don't think we'll get a real solution to this very issue since I experienced code breaks in different situations once patch #22 begins to return NULL in various methods: Even if returning NULL seems to be a viable reaction to not being able to determine a clear result, the rest of Drupal's code does not expect non-results like NULL.
Hence this is either a wrong solution or it is an API breaking change which will need some serious testing and refactoring on many places in Drupal's code base.

Maybe it's better to let #3043741: Delete base field overrides when removing entity fields they override. settle and keep looking for other situations when this issue arises.

hchonov’s picture

We still have an issue here to solve and it is the one described in the issue summary. And that problem is independent of the referenced issue about deleting the base field.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

gharel’s picture

Same issue and fix it with 2321071-25.patch, thanks
PS: Hey Renrhaf ;)

shubham.prakash’s picture

Assigned: Unassigned » shubham.prakash
shubham.prakash’s picture

Assigned: shubham.prakash » Unassigned
Status: Needs work » Needs review
FileSize
5.09 KB
DuaelFr’s picture

I face an issue that seem to be caused by this. Sadly, the #37 patch does not fix it.

My use case is not that hard to reproduce:

  1. Install Drupal using the standard profile
  2. Enable Content Moderation and Content Translation
  3. Enable translations on one of your Content Type but mark the moderation_state field as not translatable
  4. Export configuration. You should get a config_override file for the moderation_state base field.
  5. Install Drupal using the existing configuration

Expected result: Drupal is installed and your Content Type moderation_state field is not translatable
Current result: TypeError: Argument 2 passed to Drupal\Core\Entity\ContentEntityStorageBase::onFieldDefinitionUpdate() must implement interface Drupal\Core\Field\FieldDefinitionInterface, null given, called in core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php on line 205 in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php on line 463 #0 core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php(205): Drupal\Core\Entity\ContentEntityStorageBase->onFieldDefinitionUpdate(Object(Drupal\Core\Field\Entity\BaseFieldOverride), NULL)

DuaelFr’s picture

MrPaulDriver’s picture

Also works for me and solves my case \o/

Perhaps this could be reviewed by an expert, as I never want to see this error again :-)

marcusml’s picture

Patch #39 solved this issue for me as well.

herved’s picture

I can also confirm and reproduce the issue DuaelFr explained in #39 when doing an install from existing config containing a moderation_state base field override.

I investigated a bit and what happens in my case is this when attempting to save the moderation_state base field override:
- It goes in \Drupal\Core\Field\Entity\BaseFieldOverride::preSave() which calls $previous_definition = $this->getBaseFieldDefinition();
- It then goes into \Drupal\content_moderation\EntityTypeInfo::entityBaseFieldInfo()
which contains:

  if (!$this->moderationInfo->isModeratedEntityType($entity_type)) {
    return [];
  }
  ... // base field definitions below.
  

- This condition passes and returns[] early because at that point, no workflow for $entity_type (node in my case) exists because it was not imported yet.

Importing the workflow config before the moderation_state base field override (by adding a config dependency) solves it.
But this may not be ideal.

The patch from #39 makes the installation work.
However I'm not sure we can safely return NULL for all those functions, especially because a lot of contribs may not be expecting NULL.
Although this may be an edge case only when installing the site.
I don't know how to properly resolve this so maybe someone else can jump in on the review.

a.milkovsky’s picture

I have the error described in #38 on site installation from the existing config. There is also content moderation in my project.
#39 solves the problem for me.
Let's RTBC?

colan’s picture

Status: Needs review » Reviewed & tested by the community

This still needs tests, but let's RTBC for now so we can get feedback on #42 from the maintainers. It would be a waste of time to write tests if we don't have a good solution. They can set back to NW with feedback.

I'm not sure we can safely return NULL for all those functions, especially because a lot of contribs may not be expecting NULL. Although this may be an edge case only when installing the site.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

#42 sound like there is a real missing config dependency that needs fixing and the patch here is a workaround that make the dependency a kind of soft dependency. In other words it sounds like a separate bug.

herved’s picture

#45 Exactly

I believe some of the reports here may have been caused and fixed by #3043741: Delete base field overrides when removing entity fields they override.

The moderation_state issue is a different case, but not sure how to solve it because:
- workflows.workflow.editorial depends on node.type.article
- core.base_field_override.node.article.moderation_state depends on node.type.article

Should we add workflows.workflow.editorial as dependency to core.base_field_override.node.article.moderation_state ?
If so what is the best way? Maybe create a new class that extends \Drupal\Core\Field\Plugin\Field\FieldType\StringItem and implements calculateDependencies() ?

herved’s picture

Something like this?
WIP, do not use it, there is no upgrade path yet to update the config.

ejanus’s picture

I've also run into this issue.

My env: BLT(w/lightning)/D8.

After disabling lightning_scheduler and exporting the config, my Travis build fails with the following:

 [info] Undefined index: scheduled_transition_state BaseFieldOverride.php:165
TypeError: Argument 2 passed to Drupal\Core\Entity\ContentEntityStorageBase::onFieldDefinitionUpdate() must implement interface Drupal\Core\Field\FieldDefinitionInterface, null given, called in /home/travis/build/myprojWW/myproj-blt/docroot/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php on line 205 in /home/travis/build/myprojWW/myproj-blt/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php on line 463 #0 /home/travis/build/myprojWW/myproj-blt/docroot/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php(205): Drupal\Core\Entity\ContentEntityStorageBase->onFieldDefinitionUpdate(Object(Drupal\Core\Field\Entity\BaseFieldOverride), NULL)

So, far it looks like the patch #39 is working.

Watching...

herved’s picture

@ejanus You probably have a remaining base field override for "scheduled_transition_state". Deleting it should fix your issue.
In your case #3043741: Delete base field overrides when removing entity fields they override. would have deleted it when uninstalling lightning_scheduler and avoided the issue.

For the moderation_state base_field_override explained in #38 to #47, the issue is still relevant but the issue description is not really appropriate for this. I created a new issue with the patch from #47: #3129874: The "moderation_state" base field overrides cause install from existing config to fail

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

egruel’s picture

Patch #39 also solved my issue. Thank

rp7’s picture

I was getting this error for the "moderation_state" field:

TypeError: Argument 2 passed to Drupal\Core\Entity\ContentEntityStorageBase::onFieldDefinitionUpdate() must implement interface Drupal\Core\Field\FieldDefinitionInterface, null given

and the patch in #39 solved it for me, thanks.

I must add that adding workflows.workflow.editorial as a dependency to core.base_field_override.node.article.moderation_state (as suggested in #46) did fix it as well.

herved’s picture

I believe this issue should be closed as a duplicate of #3043741: Delete base field overrides when removing entity fields they override..
As for the moderation_state issue explained in #38 onwards, I opened a dedicated issue #3129874: The "moderation_state" base field overrides cause install from existing config to fail and proposed a patch there.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

eelkeblok’s picture

FWIW, I've been running into this problem while running an install from configuration, so I am not 100% convinced that #3043741: Delete base field overrides when removing entity fields they override. is able to prevent this from happing, actually. Unfortunately, this is horrible to debug as the problem only occurs well into the install process, which goes horribly slow with XDebug enabled.

herved’s picture

@eelkebok could you identify the field override causing your issue and see if it is related to #3043741: Delete base field overrides when removing entity fields they override. (by checking if the field it overrides still exists)?
Thanks

eelkeblok’s picture

Sorry, I meant to report back. It looks like it is related to the other issue; the override was for base field revision_log on media items. Not sure how we ended up with those, but the base field for revision logs on media items is called revision_log_message now (and the issue that changed it seems to be on the old media_entity contrib module; may be an issue with the distribution we've used).

I do wonder whether we can improve the error reporting here; in this case I've had to hack an echo into the core code to actually find out what base field was causing the problem. It still looks like we need to address the source - like #3043741: Delete base field overrides when removing entity fields they override. is doing - instead of ignoring the problem, but maybe we should also take into account the possibility of this situation cropping up.

James Marks’s picture

Running into the same problem when installing from existing configuration. Patch from #39 resolves the issue.

Logging values at failure in preSave() method of BaseFieldOverride.php (line 205) yields the following:
default settings: Array()
$this->settings = Array()
$this->isNew() = 1
$this->getBaseFieldDefinition() = null
$this->getName() = moderation_state
$this->getLabel() = Moderation state
$this->getType() = string

Unfortunately, unable to do further troubleshooting at this time.

herved’s picture

@James Marks, see #3129874: The "moderation_state" base field overrides cause install from existing config to fail which is the proper issue for moderation_state.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Pasqualle’s picture

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

alexpott’s picture

+++ b/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php
@@ -162,7 +169,9 @@ public function getUniqueIdentifier() {
+      if (!empty($fields[$this->getName()])) {
+        $this->baseFieldDefinition = $fields[$this->getName()];
+      }

This is really odd - a BaseFieldOverride without a base field to override is a strange concept to understand. Why does this happen and is it not an error condition.

camilo.escobar’s picture

Patch in #37 worked for me.
I was getting the error below when saving the configuration in the Content Traslation page (/admin/config/regional/content-language). It generated override files for fields of one of the entities provided by the Recurring Events module.
Then, after exporting the configuration and trying to import it in another environment, I got this:

TypeError: Argument 2 passed to Drupal\Core\Entity\ContentEntityStorageBase::onFieldDefinitionUpdate() must implement interface Drupal\Core\Field\FieldDefinitionInterface, null given, called in /app/web/core/lib/Drupal/Core/Field/Entity/Base  
  FieldOverride.php

Thanks for looking into this and providing the patch.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

robcarr’s picture

The patch at #37 has helped me on D9.5

I'd been trying to uninstall modules and getting lots WSOD/errors:

TypeError: Drupal\Core\Entity\ContentEntityStorageBase::onFieldDefinitionUpdate(): Argument #1 ($field_definition) must be of type Drupal\Core\Field\FieldDefinitionInterface, null given, called in web/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php on line 222 in Drupal\Core\Entity\ContentEntityStorageBase->onFieldDefinitionUpdate() (line 546 of web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php)

smulvih2’s picture

#37 also worked for me on D9.5.8. Was getting the same error as #68.

pcambra’s picture

Just stating that in my 9.5.10 install #37 didn't work but #39 did

Jelle_S’s picture

alfattal’s picture

Patch in #71 worked for me. I'm on Drupal 10.1.6, PHP 8.1.