WSOD after upgrading 3.0.3 to 3.0.4: Unknown column 'node_field_data.deleted' in 'where clause'

Created on 6 June 2024, 7 months ago
Updated 14 June 2024, 6 months ago

Problem/Motivation

I have a site running drupal-10.2.6 and trash-3.0.3.

When I upgraded from trash-3.0.3 to trash-3.0.4, I started getting a WSOD: checking the database log, I was getting a PHP error...

Drupal\\Core\\Database\\DatabaseExceptionWrapper: Exception in Frontpage[frontpage]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'node_field_data.deleted' in 'where clause': SELECT COUNT(*) AS "expression"
FROM
(SELECT 1 AS "expression"
FROM
"node_field_data" "node_field_data"
WHERE ("node_field_data"."deleted" IS NULL) AND (("node_field_data"."promote" = :db_condition_placeholder_0) AND ("node_field_data"."status" = :db_condition_placeholder_1))) "subquery"; Array
(
    [:db_condition_placeholder_0] => 1
    [:db_condition_placeholder_1] => 1
)
 in main() (line 19 of /app/web/index.php).

Steps to reproduce

Note that I have not tried this yet (short on time today), but if I was to guess...

  1. composer create-project drupal/recommended-project:10.2.6 "trash_wsod"
    composer require drush/drush
    composer require drupal/trash:3.0.3
    drush -y site:install minimal
    drush -y pm:install trash
      
  2. Check that it works in a web browser
  3. composer update --with-all-dependencies drupal/trash
    drush -y deploy
      
  4. Refresh a page

Proposed resolution

Not sure yet. If I were to guess, I notice that there was a post-update hook added in Add support for only enabling on certain bundles Fixed between versions 3.0.3 and 3.0.4, so maybe this issue is related to what's in the issue hook?

Remaining tasks

  1. Verify steps to reproduce and feedback
  2. Come up with a solution
  3. Write a patch
  4. Review and feedback
  5. RTBC and feedback
  6. Commit and hotfix

User interface changes

Uncertain at this time (need to come up with a solution first)

API changes

Uncertain at this time (need to come up with a solution first)

Data model changes

Uncertain at this time (need to come up with a solution first)

🐛 Bug report
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

🇨🇦Canada mparker17 UTC-4

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

Comments & Activities

  • Issue created by @mparker17
  • 🇨🇦Canada mparker17 UTC-4

    (replaced \" with " in error message in issue summary)

  • 🇮🇳India bharath-kondeti Hyderabad

    This is not reproducing with the given steps on the Drupal 10.2.6 version.

  • 🇨🇦Canada mparker17 UTC-4

    Hmm... okay. I'll see if I can figure out some better steps to reproduce when I next have time.

    For what it's worth, It took down my site and mangled my database - rolling back the code wasn't enough to fix the problem: I had to restore from yesterday's backup. For now I'm simply pinning trash to 3.0.3.

  • 🇷🇴Romania amateescu

    @mparker17, did you somehow run trash_post_update_set_enabled_entity_types_bundles() twice by any chance? That would be a situation where the enabled_entity_types property of trash.settings would become an empty array, and \Drupal\trash\EventSubscriber\TrashConfigSubscriber::onSave() would then remove the deleted field from all previously enabled entity types.

  • Status changed to Postponed: needs info 7 months ago
  • 🇷🇴Romania amateescu

    Maybe this additional check would help...

  • Status changed to Closed: works as designed 6 months ago
  • 🇨🇦Canada mparker17 UTC-4

    I figured out the problem: my deployment process was running database updates and then importing configuration immediately afterwards (i.e.: with drush deploy).

    When I looked at the deployment logs, I saw it run the post_update hook (whose description said it was updating config), then I saw it re-importing trash config, and thought "🤔 the config import is probably stomping the config changes made in the post_update hook".

    Anyway, I was able to fix it without need for the patch in #6 by...

    1. Upgrading trash locally (composer update -w drupal/trash)
    2. Running database updates (only!) locally (drush updatedb)
    3. Exporting config (drush config:export)
    4. Committing the changed config

    ... and after this, I can deploy to my shared environments normally (i.e.: they can run drush deploy, and because I committed the changed config, it works normally)

    Thanks @amateescu! (and, thanks for your patience)

    A longer description of what was happening is...

    1. When I ran database updates, it would run trash_post_update_set_enabled_entity_types_bundles(), and that would make the following change to my trash.settings config object...
      diff --git a/config/common/trash.settings.yml b/config/common/trash.settings.yml
      index 0bd1d89441..2182920fbd 100644
      --- a/config/common/trash.settings.yml
      +++ b/config/common/trash.settings.yml
      @@ -1,8 +1,8 @@
       _core:
         default_config_hash: ....
       enabled_entity_types:
      -  - media
      -  - node
      +  media: {  }
      +  node: {  }
       auto_purge:
         enabled: false
         after: '30 days'
      

      ... but this config wasn't getting exported

    2. Then, immediately after, my deploy process would import from the old configuration, reverting that change...
      diff --git a/config/common/trash.settings.yml b/config/common/trash.settings.yml
      index 0bd1d89441..2182920fbd 100644
      --- a/config/common/trash.settings.yml
      +++ b/config/common/trash.settings.yml
      @@ -1,8 +1,8 @@
       _core:
         default_config_hash: ....
       enabled_entity_types:
      -  media: {  }
      -  node: {  }
      +  - media
      +  - node
       auto_purge:
         enabled: false
         after: '30 days'
      
    3. Then when I visited the site, the code would run, expecting enabled_entity_types to be string keys mapped to an arrays (because the update hook ran); and instead found numeric keys mapped to strings (because the config:import ran afterwards)

    ... so @amateescu's patch in #6 was definitely the right idea, but ultimately, it was my site config that was wrong.

Production build 0.71.5 2024