Problem/Motivation

If field definitions and field config and field storage config get out of sync (caused by failed migrations or direct editing of config), consumers of the Field API can unknowingly trigger logic errors.
For example, Layout Builder iterates over the field map provided by EntityFieldManager, and assumes that it contains an accurate listing.
If it does not (something which is not possible to achieve through the UI, only through deployment/developer interaction), the following error occurs:

Error: Call to a member function getLabel() on null in Drupal\layout_builder\Plugin\Derivative\FieldBlockDeriver->getDerivativeDefinitions()

Proposed resolution

Develop a mechanism to review broken fields in the UI
Prevent the Field API from exposing broken fields to consumers

Remaining tasks

User interface changes

An addition to /admin/reports/fields (or a subpage)

API changes

N/A

Data model changes

N/A

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

Component: layout_builder.module » field system
Related issues: +#2985882: Workaround for "Call to a member function getLabel() after enabling layout_builder"

Opened as a new implementation issue for the previous issue that turned into a support thread.

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.

tonytheferg’s picture

Sure would be nice to resolve the Rouge fields from migration. We have one and can't find it in the db

seanr’s picture

This can also happen with a config import in progress (via drush). It'd really be nice to have this fail a bit more gracefully. BTW, is it just me or is layout_builder pretty brittle in general? Almost all of the errors I've seen on my current project have been connected to it somehow. :(

tim.plunkett’s picture

@seanr see the issue linked in #2 for a workaround.

In Layout Builder's defense, this isn't a bug in LB. LB is calling methods that are guaranteed by the Field API to work. The Field API is falling down because of malformed/invalid config in your site.

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.

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.

meanderix’s picture

This error can be triggered by the persistent bundle map not being rebuilt after configuration changes (e.g. after deleting a field from configuration). See the following issue: #3129179: Provide some way to rebuild the persistent bundle field map

meanderix’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.

longwave’s picture

FWIW as I posted over in the workaround issue, I've just had this happen to me on production during normal operation; there had been no deployments or config changes for some days and there was no unusual activity at the time. Clearing cache (from Drush, as the UI was inaccessible) fixed the problem, so I can only think that this was due to cache corruption or something like that.

tim.plunkett’s picture

Issue tags: +Needs tests
mkalkbrenner’s picture

We ran into this issue multiple times over the last two weeks, like @longwave in a running Drupal 9.5 during normal operations.
One or more calls of drush cr solved the issue for some days.
But it only happend on the production systems, never on a local development environment.

I had a look at the code and see some problematic stuff.
The key value store is database table. We use MariaDB replication. And we noticed a replication drift over the last weeks. Could it be that some action triggers the rebuild of the data but another process still reads the outdated data from a replicant which is some seconds behind the master. So this outdated data gets populated to the caches?
In that case, key value store database queries should be changed to always query the database master.

But the same could also happen if you use Redis or Memcache for fast chained caches.
The new data could be written to the key value cache within a database transaction that also invalidates the cache. But for these non-Database caches, we don't have any transaction context. So another request could still read the old data from the key value store until the transaction gets committed and write old data into the cache.

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.

catch’s picture

Status: Active » Postponed

I think the changes in #3045509: EntityFieldManager key/value field map gets out of sync, doesn't recognise bundle fields should resolve this - it removes the key/value field map entirely. Postponing on that issue.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.