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
Comment #2
tim.plunkettOpened as a new implementation issue for the previous issue that turned into a support thread.
Comment #4
tonytheferg commentedSure would be nice to resolve the Rouge fields from migration. We have one and can't find it in the db
Comment #5
seanrThis 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. :(
Comment #6
tim.plunkett@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.
Comment #9
meanderix commentedThis 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
Comment #10
meanderix commentedComment #13
longwaveFWIW 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.
Comment #14
tim.plunkettComment #15
mkalkbrennerWe 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.
Comment #17
catchI 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.