Recently read entity missing "status" entity key.

Created on 29 September 2021, about 3 years ago
Updated 8 January 2024, 12 months ago

Problem/Motivation

Hi,
When a entity of recently read is inserted the field "status" is not set but entity_key for that field is defined.
This is a problem I had when I enabled the module DANSE and this module. DANSE tried to access this field and Drupal throw an error:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Entity\EntityStorageException: Field status is unknown. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 810 of core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorage.php).
Drupal\Core\Entity\ContentEntityBase->get('status') (Line: 368)
Drupal\danse_content\Plugin\Danse\Content->isPublished(Object) (Line: 264)
Drupal\danse_content\Plugin\Danse\Content->topicsForEntity(Object) (Line: 128)
danse_content_entity_update(Object)
call_user_func_array('danse_content_entity_update', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array) (Line: 201)
Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object) (Line: 800)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object) (Line: 530)
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, 1) (Line: 685)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, 1) (Line: 455)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 801)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 119)
Drupal\recently_read\RecentlyReadService->insertEntity(Object) (Line: 31)
recently_read_entity_view(Array, Object, Object, 'full')
call_user_func_array('recently_read_entity_view', Array) (Line: 403)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_view', Array) (Line: 289)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725 ', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 786)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 377)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 578)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
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: 716)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I tried to find a solution from the side of DANSE but they pointed that the issue is the undefined entity_key for the "status" that their module tries to access. https://www.drupal.org/project/danse/issues/3224940 is the issue I opened there.

Steps to reproduce

Install the module "Recently read".
Configure the module to track any content type (for example articles).
Install and enable the DANSE modules: Drupal Audit Notification Subscription Event, and DANSE content
View a node of the content type configured in the "Recently read" module
Reload the page if the error does not appear (this is because the "Recently read" module will create the entity in the first visit)

Proposed resolution

Definde the "status" field.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

🇨🇴Colombia s_castro

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom lexsoft London

    Updating the module gives me a:
    Entity/field definitions Mismatched entity and/or field definitions
    The following changes were detected in the entity type and field definitions.
    Recently read
    The Status field needs to be installed.

  • 🇬🇧United Kingdom lexsoft London
  • 🇺🇦Ukraine Vadym.Tseiko

    Hello guys, I have a similar problem here after the module update.

  • 🇺🇦Ukraine Vadym.Tseiko

    I seek further and found that if try to create view with filter on some of fields that connected to recently read module error appears that no such database table. This problem appears after update of the module.

  • 🇺🇦Ukraine Vadym.Tseiko

    Tried: drush updb -y, re-install the module, check updates, caches cleared. I think there need to be added some hook_entity_update or base_field_definition.

  • There is a missing update hook, that adds the status field to the database table. Here's the patch file.

  • Status changed to Needs review over 1 year ago
  • First commit to issue fork.
  • @codebymikey opened merge request.
  • Added a patch updating #10 which avoids the following exception being thrown if there are already some Recently Read entities in the database:

    Exception thrown while performing a schema update. SQLSTATE[01000]: Warning: 1265 Data truncated for column 'status' at row 1: ALTER TABLE "recently_read" CHANGE `status` `status` TINYINT NOT NULL;
    

    It was missing the initial value, causing the default status value to be NULL during the initial database update. This update ensures the default value is always populated.

    I also added some missing interface methods for the entity.

  • First commit to issue fork.
  • 🇸🇮Slovenia deaom

    It's important to note, that the issues occurs with older version where the status field was introduced (1.2 I think). So if you get the latest version, you should not have the issue (this is what was probably happening with the not managing to reproduce comments). The update hook runs with no errors, I added some CS correction to the added function in the interface and also in the service (to match the interface), so leaving this to needs review but in my POV can be merged. The failing tests already have their own issue 📌 Drupal 10 Fix deprecations in tests Needs review , but if necessary the MR can be merged after the tests are passing, so test can be a blocker.

  • 🇺🇦Ukraine Vadym.Tseiko

    Applied local patch made from interdiff #14 - worked fine for me. Thanks guys.

  • Status changed to RTBC about 1 year ago
  • From what I can see locally this works, so I'm setting the status to RTBC.

  • 🇺🇦Ukraine Taran2L Lviv

    Attaching a static patch from the latest changes in the MR (for composer patching purposes)

Production build 0.71.5 2024