Column Not Found: user.name

Created on 25 February 2025, about 2 months ago

Problem/Motivation

I thought about adding this to https://www.drupal.org/project/webform/issues/3436965 🐛 Submissions results not accessible Closed: cannot reproduce , since there are some similarities, but they are different columns and showing up at a different time so I think should be reported separately.

If I try to click to sort on the User column of my log table at /admin/structure/webform/submissions/log, then I get:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user.name' in 'order clause': SELECT "log"."lid" AS "lid", "log"."uid" AS "uid", "log"."webform_id" AS "webform_id", "log"."sid" AS "sid", "log"."handler_id" AS "handler_id", "log"."operation" AS "operation", "log"."message" AS "message", "log"."variables" AS "variables", "log"."timestamp" AS "timestamp", "log"."data" AS "data", "submission"."entity_type" AS "entity_type", "submission"."entity_id" AS "entity_id" FROM "webform_submission_log" "log" LEFT OUTER JOIN "users_field_data" "u" ON log.uid = u.uid LEFT OUTER JOIN "webform_submission" "submission" ON log.sid = submission.sid ORDER BY "user"."name" ASC LIMIT 50 OFFSET 0; Array ( ) in Drupal\webform_submission_log\WebformSubmissionLogManager->loadByEntities() (line 134 of modules/contrib/webform/modules/webform_submission_log/src/WebformSubmissionLogManager.php).
Drupal\Core\Database\StatementWrapperIterator->execute(Array, Array) (Line: 851)
Drupal\Core\Database\Connection->query('SELECT "log"."lid" AS "lid", "log"."uid" AS "uid", "log"."webform_id" AS "webform_id", "log"."sid" AS "sid", "log"."handler_id" AS "handler_id", "log"."operation" AS "operation", "log"."message" AS "message", "log"."variables" AS "variables", "log"."timestamp" AS "timestamp", "log"."data" AS "data", "submission"."entity_type" AS "entity_type", "submission"."entity_id" AS "entity_id"
FROM
{webform_submission_log} "log"
LEFT OUTER JOIN {users_field_data} "u" ON log.uid = u.uid
LEFT OUTER JOIN {webform_submission} "submission" ON log.sid = submission.sid
ORDER BY "user"."name" ASC
LIMIT 50 OFFSET 0', Array, Array) (Line: 524)
Drupal\Core\Database\Query\Select->execute() (Line: 329)
Drupal\Core\Database\Query\SelectExtender->execute() (Line: 81)
Drupal\Core\Database\Query\PagerSelectExtender->execute() (Line: 134)
Drupal\webform_submission_log\WebformSubmissionLogManager->loadByEntities(NULL, NULL, NULL, Array) (Line: 109)
Drupal\webform_submission_log\Controller\WebformSubmissionLogController->overview(NULL, NULL, NULL, NULL)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

As far as I know, the only requirements are to install it, have some webform submissions (some of those are from anonymous, if that matters), go to the log table view, and click on the User header to try to sort by user.

This is true on my production environment with:
Drupal core 10.3.13
Webform 6.2.8

And on my developer environment with:
Drupal core 10.4.3
Webform 6.3.0-beta1

I've tried it a couple times with some other versions in between as well, but those are the two I can currently replicate.

Proposed resolution

The error is accurate in that there is no user.name field in the webform_submission table. There is a uid in that table instead, so maybe it was trying to do something with that.

That suggests it is trying to sort alphabetically by the user's name. I found in src/Controller/WebformSubmissionLogController.php, line 104:

    $header['uid'] = ['data' => $this->t('User'), 'field' => 'user.name', 'class' => [RESPONSIVE_PRIORITY_LOW]];

I think that's the culprit. The header says uid, then the field value says user.name, and there is no user.name to be able to sort by.

I could change that from user.name to uid and the sort will work, but it is sorting by the ID, not by their name. That is much better than a fatal error (most of the time in my case I don't really need them truly sorted, just grouped enough to get a sense of repeats), but certainly is confusing if you haven't looked at the code, since it does suggest in the interface that it would be sortable by name. Plus of course it looks like the code was trying to do, so me reverting it to sorting by uid would be regression.

🐛 Bug report
Status

Active

Version

6.3

Component

Code

Created by

🇨🇦Canada ryanrobinson_wlu

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

Comments & Activities

Production build 0.71.5 2024