Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There is a bug in line 211 in the file
\core\lib\Drupal\Core\Entity\ContentEntityBase.php
The line
if (!$this->getFieldDefinition($field_name)->isTranslatable()) {
leads to a fatal error, if $this->getFieldDefinition($field_name) is null
My suggestion:
$translatable = FALSE;
if (!empty($this->getFieldDefinition($field_name))) {
$translatable = $this->getFieldDefinition($field_name)
->isTranslatable();
}
if (!$translatable) {
Greetings
Berthold
Comment | File | Size | Author |
---|---|---|---|
#23 | 3044676-23.patch | 2.14 KB | plach |
#22 | 3044676-22.patch | 2.17 KB | plach |
#21 | 3044676-21.patch | 1.87 KB | plach |
Comments
Comment #2
cilefen CreditAttribution: cilefen as a volunteer commentedThe issue title mentions the beta. Is this a regression as compared to 8.6.x?
I fixed tags.
Comment #3
larowlanComment #4
larowlanI think we also have
hasFieldDefinition
Comment #5
plachThe only line I could find matching the reported one is https://git.drupalcode.org/project/drupal/blob/8.8.x/core/lib/Drupal/Cor.... There we are populating entity keys and those are not supposed to be missing, otherwise many other things will break. This seems like a missing update to me, unless some contrib/custom code is altering entity keys.
@BLausch:
$field_name
?Comment #6
plachComment #7
plachComment #8
BLausch CreditAttribution: BLausch commented@The only line I could find matching the reported one is
As I wrote above:
There is a bug in line 211 in the file \core\lib\Drupal\Core\Entity\ContentEntityBase.php
It doesn't matter if it is version 8.7 or 8.8. It is the same code.
@Are you sure all DB updates were run successfully?
Yes
Comment #9
BLausch CreditAttribution: BLausch commentedThe error messages starts with:
Comment #10
plachSorry, somehow I managed to miss that :)
Luckily 211 is the line I identified previously, so #5 is still valid. Could you apply this patch and report the output?
Comment #11
BLausch CreditAttribution: BLausch commentedof course
here is the output (only the first line)
Comment #12
plachThanks for the report @BLausch, but to able to tell what's going on I need the full output, to be able to figure out the code path and hopefully replicate the problem in my environment. That's the easiest way to figure out what's going on. Also, the script should output the name of the field triggering the error, but I don't see it above. That might also be key to understanding the issue.
Comment #13
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commentedBetter to use 'hasField($field_name)' to check if the field is avaialbe
Not sure these two methods can always return a valid cross field.
$this->getEntityType()->getKeys()
\Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityTypeId, $this->bundle())
Comment #14
BLausch CreditAttribution: BLausch commented@Thanks for the report @BLausch, but to able to tell what's going on I need the full output
My first attempt crashes the browser (firefox). When I reloaded the page, I had to reboot the system.
The output is obviously to long.
But I is easy to reproduce the error, just create an entity and view the entity.
The error should appear immediately.
Greetings Berthold
Comment #15
BLausch CreditAttribution: BLausch commented@Joseph Zhao
Your patch works as well as mine.
Berthold
Comment #16
BLausch CreditAttribution: BLausch commentedThere seem to be more problems with entities.....
If you add an entity-type with a title field included you get an error, while saving a new content of the entity:
Drupal\Core\Entity\EntityStorageException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'title' in 'field list'
Comment #17
BLausch CreditAttribution: BLausch commentedForget about the title thing.
I figured it out. The reason for the error was the eck module.
I used this one which caused the error
Switching back to this one
and the error is gone.
The dev-version did not create a title column in the mysql-table :-(
Comment #18
plachOk, if also the error initially reported is triggered by an entity provided by ECK, then this might be it needing some adjustments due to https://www.drupal.org/node/3040966.
Could you try this new version of the patch that should produce a lighter output and report back? Having the full output including the offending definition name would be very important.
Comment #19
BLausch CreditAttribution: BLausch commentedno problem at all this time.
here is the error (full error code)
Comment #20
plachThanks, still no luck in figuring this out. Could you try this new patch? It will generate a downloadable report rather than printing the output on screen.
Comment #21
plachWrong patch, sorry
Comment #22
plachBetter patch including more info, sorry for the noise.
Comment #23
plachWrong patch, again, sigh
Comment #24
BLausch CreditAttribution: BLausch commentedI will apply the patch and send you the file as soon as possible.
Berthold
Comment #25
BLausch CreditAttribution: BLausch commentedI tried it, but it is not possible.
Even if I increase the php-memory to 20 GB (yes, GB) I got the error:
Probably this is not a good idea.
I guess, it is easy for you to reproduce the error.... isnt' it.
Greetings
Berthold
Comment #26
mradcliffeThis could be similar to what I've found after a migration re: #3008202: Migrating more than 1 entity reference field instance fails. I've found that the field definition cache can be stale for some entities that don't have field values. I was able to workaround the issue by clearing the entity cache before saving an entity reference field.
Comment #27
pandaski CreditAttribution: pandaski at govCMS (Australian Government Department of Finance) commented#26 entity cache is a good point
Comment #28
plachWell, in my local env that script runs successfully with a memory limit of 512MB, so I was assuming it would work just fine. That fact that the memory usage is that high is definitely abnormal. I will try to come up with a lighter version, but for now I think we should go back to the good practice and try to come up with some steps to reproduce the error.
At the moment from the stack trace above, I can only tell the error is happening while running a view, but I don't even know which entity type is being listed. However, given the error, it might not be that important, because the root problem seems to be a broken state of the entity type keys, which is what the report was supposed to provide info about.
Definitely not, no idea of what's going on.
Comment #29
BLausch CreditAttribution: BLausch commentedOK I figured it out, how to reproduce the error.
Add an entity (for example: t2) with all default fields, which are:
Created field
Change field
Author field
Title field
(Title field is the important)
After saving your entity you edit it and uncheck the title field.
This causes the error.
In the database, the table: t2_field_data still has the column title, the value is NULL.
There is still another error:
If you delete the t2-Entity, the two tables:
t2
and
t2_field_data
stay in the database. That causes more errors, but this is another story :-)
Greetings
Berthold
Comment #30
plachDo you mean through ECK? Can you provide a list of modules to enable? Or at least could you provide the list of modules enabled on your site?
Comment #31
BLausch CreditAttribution: BLausch commentedof course through ECK
only activated this module.
Comment #32
BLausch CreditAttribution: BLausch commentedDid you succeed in reproducing the error ?
Is there something missing ?
Greetings
Berthold
Comment #33
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI tried to reproduce the problem using the latest version of ECK and Drupal 8.7.0 but I couldn't get error reported in the issue summary.
In any case, moving this issue to the ECK issue queue.
Comment #34
andres.torres CreditAttribution: andres.torres commentedI can confirm the issue on a fresh Drupal 8.7.4 install, Content Translation enabled with ECK alpha 5. Issue triggers when adding a translation to a field on a Bundle.
The website encountered an unexpected error. Please try again later.
Error: Call to a member function isTranslatable() on null in Drupal\Core\Entity\ContentEntityBase->__construct() (line 211 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
Drupal\Core\Entity\ContentEntityBase->__construct(Array, 'activity', 'hass_maintenance', Array) (Line: 530)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->mapFromStorageRecords(Array) (Line: 449)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->getFromStorage(Array) (Line: 415)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->doLoadMultiple(Array) (Line: 292)
Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array) (Line: 250)
Drupal\Core\Entity\EntityStorageBase->load('1') (Line: 72)
Drupal\Core\Entity\Plugin\DataType\EntityReference->getTarget() (Line: 37)
Drupal\Core\TypedData\DataReferenceBase->getValue() (Line: 140)
Drupal\Core\Field\FieldItemBase->__get('entity') (Line: 353)
Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormBase->prepareFormState(Object, Object, ) (Line: 231)
Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormComplex->formElement(Object, 0, Array, Array, Object) (Line: 335)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 85)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object, NULL) (Line: 552)
Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormBase->form(Object, Array, Object) (Line: 177)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 125)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 127)
Drupal\node\NodeForm->form(Array, Object) (Line: 117)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 519)
Drupal\Core\Form\FormBuilder->retrieveForm('node_worked_day_edit_form', Object) (Line: 276)
Drupal\Core\Form\FormBuilder->buildForm('node_worked_day_edit_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comment #35
andres.torres CreditAttribution: andres.torres commentedWhen enabling the Title field for the Bundle, the issue is gone, so it seems that the NULL value comes when the bundle has no title set.
Comment #36
Irving Jair CreditAttribution: Irving Jair commentedThanks All, #13 that validation worked for me, at least for the moment.
Comment #37
Gogowitsch CreditAttribution: Gogowitsch as a volunteer and at QuoData GmbH Quality & Statistics for ÖQUASTA commentedFor future Googlers: I ran into the
Call to a member function isTranslatable() on null
exception when the following were put together:I am not using ECK, but Core line numbers match.
It happened because translatable entity types have a
default_langcode
field as a key.