Problem/Motivation
When a Views table display has the field “Views result counter” (row counter) and that column is made sortable (click-sort in table header), clicking the header triggers an SQL query with ORDER BY "unknown", which fails with SQLSTATE[42S22]: Column not found: 1054 Unknown column 'unknown' in 'order clause'.
Steps to reproduce
- Go to /admin/structure/views and edit the core view People (display id: user_admin_people) or create a new View listing users.
- Set the display format to Table.
- Add the field Global: Views result counter (or the Views “result counter” field).
- In the Table settings, enable the column as sortable (click-sort).
- Visit the view page (e.g. /admin/people) and click the table header for that counter column.
Proposed resolution
Update the Views data definition for the built-in “counter” field to explicitly mark it as non-sortable by adding 'click sortable' => FALSE
Additionally, introduce a post-update hook (views_post_update_counter_field_not_sortable()) so that the updated Views data definition is picked up on existing sites.
Expected result
Either:
- The UI should not allow enabling click-sort for the result counter field, or
- Clicking the header should not add an invalid ORDER BY and should fail gracefully / be ignored.
Actual result
A query is generated with an invalid ORDER BY and the page errors:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'unknown' in 'order clause'
... ORDER BY "unknown" ASC ...| Comment | File | Size | Author |
|---|---|---|---|
| #11 | Screenshot 2026-03-11 at 7.18.53 PM.png | 126.92 KB | sivaji_ganesh_jojodae |
| #11 | Screenshot 2026-03-11 at 7.16.59 PM.png | 337.8 KB | sivaji_ganesh_jojodae |
| #2 | drupal-core-views-counter-disable-click-sortable-11.2.x.patch | 486 bytes | mike-michal |
Issue fork drupal-3574506
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 #2
mike-michal commentedAttached patch sets views.counter field as 'click sortable' = FALSE in views_views_data().
This prevents enabling click-sort for Views result counter and avoids ORDER BY "unknown" SQL errors.
Tested:
- Core: 11.2.10
- Views: /admin/people (People[user_admin_people]) table + Views result counter sortable previously caused SQLSTATE[42S22].
- After patch: counter is not click-sortable; error no longer occurs.
Comment #4
quietone commentedHi, Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.
Comment #5
quietone commentedChanging tags per Issue tags field and Issue tags -- special tags
Comment #8
mike-michal commentedHi @quietone
Thanks for the guidance.
The patch has been applied to `main` and an MR has been created/updated accordingly.
Please let me know if there is something else I can do.
Kind regards,
Michał, Mike Kozłowski.
Comment #9
lendudeActually major since it throws an exception.
This fixes it, nice.
No point in trying to clean up existing config, the format settings are never updated with any changes made in the UI anyway so they are a mess anyway. Tested that the click sorting disappears from the View even if the config still says it is click sortable, so this fixes existing Views too.
Comment #10
sivaji_ganesh_jojodae commentedThe patch affects the Table sort settings of View result counter.
However the View page is broken with the following SQL error once View result counter is added.
Comment #11
sivaji_ganesh_jojodae commentedI tested this on a fresh installation, and the patch works as expected.
Please see the screenshots below for reference.
Views table settings
Admin people listing with View result counter
Comment #12
quietone commentedComment #13
alexpottI agree that we should fix this first as it is an easy way to cause an SQL error. But I also think we should file a follow-up to fix existing views as the view configuration is only fixed if you return to the table settings and press save.
Also in order for the view to be fixed we need to rebuild views data so we should be adding an empty post update function so we can release this fix in a bug release.
@lendude I don't really understand what you mean by
The format settings were definitely updated when I tested going back to the table settings and pressing update after applying this MR.
Comment #14
alexpottRe #13 - I think the only thing we need to do here is to add an empty post update function to views.post_update.php
Comment #15
sivaji_ganesh_jojodae commentedAdded an empty post-update hook to views.post_update.php.
Comment #16
mike-michal commentedWow. One line of code and such a long journey? ;)
Comment #17
smustgrave commentedThis one still appears to need a follow up so leaving in review.
Comment #18
smustgrave commentedThis one needs a reroll now, also summary could use an update as it's missing the required proposed solution section.
Comment #19
mike-michal commentedReroll?
Comment #20
sivaji_ganesh_jojodae commentedUpdated the Issue summary and fixed the merge conflict.
Comment #21
mike-michal commentedSorry guys for my confusion. I am new to this process.
I thought that this simple and obvious, imho, change is a great opportunity to understand how to contribute. But if this one, simple line of code takes so long way I can't imagine how it goes with something a little bit more complex ;)
Comment #22
smustgrave commentedOpened #3588188: Fix existing views with click sortable per #3574506 so removing follow up tag.
@mike-michal this issue was waiting on a follow up ticket to be created per #14,.
Feedback has been address with the empty hook.
Comment #23
mike-michal commented@smustgrave it would be nice if someone could explain me in details what is going on here. Maybe I could try to contribute more frequently. Crossed fingers for happy end of this one ;) Thanks a lot for all your efforts. Mike.
Comment #24
alexpottCommitted 71f4885 and pushed to main. Thanks!
Committed 76ce09f and pushed to 11.x. Thanks!
Committed 326940f and pushed to 11.3.x. Thanks!
Comment #28
alexpott@mike-michal the thing that makes a change like this hard is that there are existing views configs that need fixing - that's been descoped for a follow-up in #3588188: Fix existing views with click sortable per #3574506. So the fix is simple but the updating of existing views is not that easy and should only happen in the minor update whereas this can go in a patch release.