Symptoms:

Attempting to create a node at /node/add/NODE_TYPE as a non-admin user causes the following error:

Drupal\Core\Database\InvalidQueryException: Query condition 'group_content.entity_id IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 76 of core/lib/Drupal/Core/Database/Query/Condition.php).
Drupal\Core\Database\Query\Select->condition('group_content.entity_id', Array, 'IN') (Line: 58)
Drupal\Core\Entity\Query\Sql\Condition->compile(Object) (Line: 167)
Drupal\Core\Entity\Query\Sql\Query->compile() (Line: 86)
Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 508)
Drupal\Core\Entity\EntityStorageBase->loadByProperties(Array) (Line: 140)
gnode_node_access(Object, 'delete', Object)
call_user_func_array('gnode_node_access', Array) (Line: 393)
Drupal\Core\Extension\ModuleHandler->invokeAll('node_access', Array) (Line: 76)
Drupal\Core\Entity\EntityAccessControlHandler->access(Object, 'delete', Object, 1) (Line: 73)
Drupal\node\NodeAccessControlHandler->access(Object, 'delete', NULL, ) (Line: 183)
Drupal\node\Entity\Node->access('delete') (Line: 305)
Drupal\node\NodeForm->actions(Array, Object) (Line: 194)
Drupal\Core\Entity\EntityForm->actionsElement(Array, Object) (Line: 123)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 517)
Drupal\Core\Form\FormBuilder->retrieveForm('node_project_form', Object) (Line: 276)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 53)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object) (Line: 118)
Drupal\node\Controller\NodeController->add(Object)
call_user_func_array(Array, Array) (Line: 128)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 577)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 129)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 102)
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: 62)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 55)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 637)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce:

1. Create a group type named "team"
2. Create a node type named "organization"
3. Install "Group node (organization)" for "team" group type (/admin/group/types/manage/team/content)
4. Create a new user
5. Grant that user the core permission "Organization: Create new content"
6. Log in as the new user and visit /node/add/organization

Comments

milesw created an issue. See original summary.

milesw’s picture

Title: Fatal error when creating a node outside a group » Fatal error when creating a node at /node/add/NODE_TYPE
milesw’s picture

Status: Active » Needs review
StatusFileSize
new946 bytes

Error is being caused by gnode_node_access() querying for group content when the node does not yet have an ID.

Patch here checks if the node is new before querying for group content.

kristiaanvandeneynde’s picture

Issue tags: +Deeson sprint

Oh wow, great catch! Will definitely be added to the dev branch during today's sprint!

johnennew’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.03 KB

Confirmed this happens and the patch fixes it. There is a typo on the initial creation of the $group_contents variable (says $group_content) - here is an updated patch. Also, replaced a !count with an empty as discussed with @kristiaanvandeneynde - two minor changes so changing to RTBC...

kristiaanvandeneynde’s picture

Interestingly, this seems like a minor bug in core in NodeForm::actions().

    $element['delete']['#access'] = $node->access('delete');
    $element['delete']['#weight'] = 100;

    return $element;

It doesn't check whether the entity is new or not, whereas the parent actions() call only sets the delete button if the entity exists already. Anyways, fixing this as we should account for core/contrib calling update/view/delete on new entities even if that makes no sense at all.

Will commit with a minor refactor.

kristiaanvandeneynde’s picture

Status: Reviewed & tested by the community » Fixed

Committed and gave milesw author credit as us Deeson guys were mostly nitpicking anyways :)

milesw’s picture

Thanks guys, and sorry for the rushed patch. :)

Status: Fixed » Closed (fixed)

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

The last submitted patch, 3: group-gnode-2706893-3-error-creating-node.patch, failed testing.

Status: Closed (fixed) » Needs work

The last submitted patch, 5: group-fatal_error_node_add_form-2706893-5.patch, failed testing.

kristiaanvandeneynde’s picture

Status: Needs work » Closed (fixed)

Bad testbot! :)