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
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 3239926-MR9-v3.patch | 3 KB | taran2l |
Issue fork recently_read-3239926
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
dstojanovski commentedThe "Status" field is defined and the module is tested with the DANCE module. It works fine.
Comment #5
lexsoft commentedUpdating 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.
Comment #6
lexsoft commentedComment #7
vadym.tseiko commentedHello guys, I have a similar problem here after the module update.
Comment #8
vadym.tseiko commentedI seek further and found that if try to create a view with a filter on some of the fields that are connected to the recently read module error appears that no such database table. This problem appears not after the update of the module but in compatibility with some other modules, in my case views module with relation to this module.
Comment #9
vadym.tseiko commentedTried: drush updb -y, re-install the module, check updates, caches cleared, reconfigured view, as soon as I add a relation to recently_read I get this error. I think there needs to be added some hook_entity_update or base_field_definition.
Comment #10
admirlju commentedThere is a missing update hook, that adds the status field to the database table. Here's the patch file.
Comment #11
admirlju commentedComment #14
codebymikey commentedAdded a patch updating #10 which avoids the following exception being thrown if there are already some Recently Read entities in the database:
It was missing the initial value, causing the default status value to be
NULLduring the initial database update. This update ensures the default value is always populated.I also added some missing interface methods for the entity.
edit: NB: this part of the code:
is somewhat redundant at the moment since the update manager doesn't attempt to do any content population if the 'status' field already exists.
Comment #16
deaom commentedIt'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 #3382214: Drupal 10 Fix deprecations in tests, but if necessary the MR can be merged after the tests are passing, so test can be a blocker.
Comment #17
vadym.tseiko commentedApplied local patch made from interdiff #14 - worked fine for me. Thanks guys.
Comment #18
admirlju commentedFrom what I can see locally this works, so I'm setting the status to RTBC.
Comment #19
taran2lAttaching a static patch from the latest changes in the MR (for composer patching purposes)