There is an error when trying to delete any entity:

The website encountered an unexpected error. Please try again later.
Error: Call to a member function getColumns() on boolean in Drupal\Core\Entity\Query\Sql\Tables->addField() (line 168 of core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).

Drupal\Core\Entity\Query\Sql\Tables->addField('endpoints.entity_type', 'INNER', NULL) (Line: 44)
Drupal\Core\Entity\Query\Sql\Condition->compile(Object) (Line: 39)
Drupal\Core\Entity\Query\Sql\Condition->compile(Object) (Line: 162)
Drupal\Core\Entity\Query\Sql\Query->compile() (Line: 81)
Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 431)
relation_entity_delete(Object)
call_user_func_array('relation_entity_delete', Array) (Line: 402)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_delete', Array) (Line: 169)
Drupal\Core\Entity\EntityStorageBase->invokeHook('delete', Object) (Line: 418)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('delete', Object) (Line: 369)
Drupal\Core\Entity\EntityStorageBase->delete(Array) (Line: 692)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete(Array) (Line: 366)
Drupal\Core\Entity\Entity->delete() (Line: 70)
Drupal\Core\Entity\ContentEntityDeleteForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 583)
Drupal\Core\Form\FormBuilder->processForm('node_page_delete_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('node_page_delete_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 572)
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}()
call_user_func_array(Object, Array) (Line: 139)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 626)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Also, in code, $relation->endpoints returns NULL, so I think the problem is something about endpoints field.

Comments

sanja_m created an issue. See original summary.

slashrsm’s picture

Tested this and wasn't able to reproduce. Here is what I did:

1. Created relation type that references any node
2. Created 2 nodes
3. Created relation between them Relation::create(['relation_type' => 'test', 'endpoints' => [['entity_type' => 'node', 'entity_id' => 1, 'r_index' => 0], ['entity_type' => 'node', 'entity_id' => 2, 'r_index' => 1]]])
4. Made sure relation appears in /admin/content/relation
5. Deleted relation $relation->delete()
6. Made sure no fatal was thrown.
7. Made sure relation disappeared from /admin/content/relation

Could you provide steps that brought you to that error?

sanja_m’s picture

Status: Active » Needs review
StatusFileSize
new2.91 KB

Steps to reproduce:
1. Enable relation module
2. Do not create any relation type or relation
3. Try to delete any node - error appears, but the node has been deleted.

Added a quick patch that solves this.

And for the $relation->endpoints returning NULL still need to check, it's probably a bug in an issue where I detected this entity deletion problem - #2694321: Convert action_info functions to action plugins.

Status: Needs review » Needs work

The last submitted patch, 3: 2704047-3.patch, failed testing.

The last submitted patch, 3: 2704047-3.patch, failed testing.

sanja_m’s picture

Status: Needs work » Needs review
StatusFileSize
new2.84 KB

Re-rolled patch from #3.

CTaPByK’s picture

Status: Needs review » Reviewed & tested by the community

Code look ok, just simple check if we have any relation. Patch is definitely help with this error.

slashrsm’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/relation.module
@@ -345,34 +345,41 @@ function relation_entity_delete(EntityInterface $entity) {
+  $relations_exist = \Drupal::entityTypeManager()->getStorage('relation')->getQuery()
+    ->range(0, 1)
+    ->execute();

I would rather check if there are any relation types defined (as this is actually the problem).

We also need test for this.

sanja_m’s picture

Status: Needs work » Needs review
StatusFileSize
new5.84 KB
new2.75 KB
new2.75 KB

Added test coverage and left check for relations instead for relation types, because when deleting relation types (when there are no relations) error appears again.

Status: Needs review » Needs work

The last submitted patch, 9: 2704047-9-test-only.patch, failed testing.

The last submitted patch, 9: 2704047-9-test-only.patch, failed testing.

CTaPByK’s picture

Status: Needs work » Reviewed & tested by the community

This test looks ok, patch also. You should upload test-only patch first to avoid needs work status.

slashrsm’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/relation.module
@@ -310,36 +310,42 @@ function relation_entity_delete(EntityInterface $entity) {
+  $relations_exist = \Drupal::entityTypeManager()->getStorage('relation')->getQuery()
+    ->range(0, 1)
+    ->execute();

Let's use count query then.

sanja_m’s picture

Status: Needs work » Needs review
StatusFileSize
new2.71 KB
new5.79 KB
new2.18 KB

Added count query and fixed some bugs in test after #2697931: Clean-up RelationType entity class.

The last submitted patch, 14: 2704047-14-test-only.patch, failed testing.

The last submitted patch, 14: 2704047-14-test-only.patch, failed testing.

CTaPByK’s picture

Status: Needs review » Reviewed & tested by the community

RTBC

  • slashrsm committed ec88831 on 8.x-1.x authored by sanja_m
    Issue #2704047 by sanja_m, slashrsm, CTaPByK: Error when deleting...
slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.