Fix WSOD when no content is configured for locking

Created on 14 December 2020, over 3 years ago
Updated 10 April 2024, 5 months ago

Problem/Motivation

There is a php exception on the overview page ("admin/content/locked-content") after enabling and not configuring the content_lock module:

PHP message: Uncaught PHP Exception Drupal\Core\Database\DatabaseExceptionWrapper: "Exception in Locked content[locked_content]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'timestamp' in 'field list': SELECT COUNT(*) AS "expression"
FROM
(SELECT DISTINCT "node_field_data"."nid" AS "nid", "users_field_data_content_lock"."uid" AS "users_field_data_content_lock_uid", timestamp AS "timestamp", langcode AS "langcode", 1 AS "expression"
FROM
{node_field_data} "node_field_data"
INNER JOIN {users_field_data} "users_field_data_content_lock" ON uid = users_field_data_content_lock.uid
WHERE ""."timestamp" <> :db_condition_placeholder_0) "subquery"; Array
(
    [:db_condition_placeholder_0] => 0
)
" at docroot/core/modules/views/src/Plugin/views/query/Sql.php line 1541" while reading response header from upstream, client: 127.0.0.1, server: , request: "GET /admin/content/locked-content HTTP/1.1",

Proposed resolution

Only allow access to the provided view if node is in the listed of lockable entity types.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany volkerk

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany skrug Bamberg

    I provide a patch file containing changes of the branch. Worked for me.

  • πŸ‡©πŸ‡ͺGermany skrug Bamberg

    Patch renamed with issue number

  • First commit to issue fork.
  • Pipeline finished with Canceled
    6 months ago
    Total: 132s
    #123769
  • Pipeline finished with Failed
    6 months ago
    Total: 224s
    #123773
  • Pipeline finished with Failed
    6 months ago
    Total: 228s
    #123783
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    This doesn't fix the problem. I think the problem requires a different solution. The view is assuming that nodes are configured to use the lock when they are not. Hence the problem. I think we should only grant access to the view when node is in the lockable entity types.

  • Pipeline finished with Success
    6 months ago
    Total: 224s
    #123788
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Also I think that this clear needs to not be in the form. In needs to be in \Drupal\content_lock\EventSubscriber\SettingsSaveEventSubscriber::onSave

    With something like

          if ($event->isChanged('types') && \Drupal::moduleHandler()->moduleExists('views')) {
            Views::viewsData()->clear();
          }
    
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    Clearing views data is not enough. If no content is enabled, this still would fail with

    Drupal\Core\Database\DatabaseExceptionWrapper: Exception in Locked content[locked_content]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'timestamp' in 'field list': SELECT COUNT(*) AS "expression" FROM (SELECT DISTINCT "node_field_data"."langcode" AS "node_field_data_langcode", "users_field_data_content_lock"."langcode" AS "users_field_data_content_lock_langcode", "node_field_data"."nid" AS "nid", "users_field_data_content_lock"."uid" AS "users_field_data_content_lock_uid", timestamp AS "timestamp", langcode AS "langcode", 1 AS "expression" FROM "node_field_data" "node_field_data" INNER JOIN "users_field_data" "users_field_data_content_lock" ON uid = users_field_data_content_lock.uid WHERE ""."timestamp" <> :db_condition_placeholder_0) "subquery"; Array ( [:db_condition_placeholder_0] => 0 ) in main() (line 19 of index.php).
    

    We probably need to add the columns no matter if the content is enabled or not. Another alternative might be having a controller that takes the view url when no content is enabled, and renders the view itself when some content is enabled?
    We probably want to check how content moderation handles this in core, as it's a similar scenario.

  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    @alexpott I wrote #11 without seeing your #9 and #10 and came to similar conclusion. Will work on this tomorrow.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Question, the current issue summary mentions shipping with default config having nodes enabled. Is that a viable approach?

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @smustgrave then the module will have to depend on node and you can still get into this situation by removing node configuration.

  • Pipeline finished with Failed
    6 months ago
    Total: 226s
    #129938
  • Status changed to Needs review 6 months ago
  • πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

    So I've added a custom views access plugin that can check if any types are configured.

    This custom views access plugin also adds a custom access checker to the route, so when no content type is configured will return an Access denied.

    As we are adding a new method to the interface this might not be backwards compatible.

  • Pipeline finished with Failed
    6 months ago
    Total: 266s
    #129978
  • Pipeline finished with Failed
    6 months ago
    Total: 226s
    #129991
  • Pipeline finished with Failed
    6 months ago
    #130003
  • Pipeline finished with Running
    6 months ago
    #130014
  • Status changed to Needs work 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    So manually tested and when I go to the view page I get an access denied.

    Tried adding a test for it but get

    Drupal\Core\Config\Schema\SchemaIncompleteException : Schema errors for views.view.locked_content with the following errors: views.view.locked_content:display.default.display_options.access.options missing schema

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    When I open the view I see

    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'timestamp' in 'field list': SELECT COUNT(*) AS "expression" FROM (SELECT DISTINCT "node_field_data"."langcode" AS "node_field_data_langcode", "users_field_data_content_lock"."langcode" AS "users_field_data_content_lock_langcode", "node_field_data"."nid" AS "nid", "users_field_data_content_lock"."uid" AS "users_field_data_content_lock_uid", timestamp AS "timestamp", langcode AS "langcode", 1 AS "expression" FROM "node_field_data" "node_field_data" INNER JOIN "users_field_data" "users_field_data_content_lock" ON uid = users_field_data_content_lock.uid WHERE ""."timestamp" <> :db_condition_placeholder_0) "subquery"; Array ( [:db_condition_placeholder_0] => 0 )

  • Status changed to Needs review 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    I see the access denied was intentional.

    I added a simple test (can be expanded on later) that checks this.

    For the schema issue since this access check doesn't need options I removed that from the view.

    Thoughts?

  • Pipeline finished with Failed
    6 months ago
    Total: 207s
    #130049
  • Pipeline finished with Failed
    6 months ago
    Total: 226s
    #130053
  • Pipeline finished with Failed
    6 months ago
    Total: 3347s
    #130057
  • Pipeline finished with Success
    5 months ago
    Total: 297s
    #130100
  • Status changed to RTBC 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Removed the pagination_header line and tests are green. Since I just added the tests I think it's fine to mark.

    Once this lands I'll expand on the tests in πŸ“Œ Extend test coverage Needs work which has a last step to add views integration testing.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Assigning credit.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    We could file a follow-up to make the new views access plugin configurable.

  • Pipeline finished with Skipped
    5 months ago
    #130540
  • Status changed to Fixed 5 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024