Mismatched entity and/or field definitions for Duplicates checksum field

Created on 19 April 2024, 2 months ago

Problem/Motivation

We recently installed the module to local, staging and production environment. The module installed fine in local and staging environments but during production installation something seems to have gone wrong and the duplicates_checksum column was not created to media_field_data table.

The production installation was done with drush deploy and that went fine without errors.

Looking at similar errors from other projects, it seems like this module does not define the field in the module schema nor does it contain any configuration for it.

We tried to also uninstall and install the module again but that was not successful because it was giving the same error during uninstall

 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'duplicates_checksum' in 'where clause': SELECT 1 AS "expression"  
  FROM                                                                                                                      
  "media_field_data" "t"                                                                                                    
  WHERE "duplicates_checksum" IS NOT NULL                                                                                   
  LIMIT 1 OFFSET 0; Array                                                                                                   
  (                                                                                                                         
  )     

This basically broke all media uploads because it was causing the following SQL error during media upload.

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'duplicates_checksum' in 'where clause': SELECT COUNT(*) AS "expression" FROM (SELECT 1 AS "expression" FROM "media_field_data" "media_field_data" WHERE "duplicates_checksum" = :db_condition_placeholder_0) "subquery"; Array ( [:db_condition_placeholder_0] => Q3leyRULACNkwuu9pwJAZBmyLzyD_7ByqgFG8kcJJjo ) funktiossa Drupal\media_duplicates\ChecksumStatistics->checksumExists() (rivi 56 tiedostossa /var/www/builds/2024-04-17.14-07-38.commit--acceb016/web/modules/contrib/media_duplicates/src/ChecksumStatistics.php).

It seems like the field is created in the .module file https://git.drupalcode.org/project/media_duplicates/-/blob/2.x/media_dup... but for some reason this didn't succeed.

I was looking at similar issues and it seems like for example [#2655844) has fixed it by removing the entity_base_field_info hook and instead using configurations instead. I am not 100% sure if this would work here also, it might be some core functionality that this module is at the moment relying on, but it seems it's really hard to recover from a failed installation. We ended up altering the table manually and this fixed the media upload but we are now left with the status report error that the entity types are mismatched.

Steps to reproduce

No clear steps because the module installed fine to two enviroments and failed without any errors in third.

Proposed resolution

Find a way to recover from the error and perhaps make the module installation more fool proof between different environments. This might be related to drush deploy where modules are installed from configurations and not with drush cim or from UI.

Remaining tasks

TBA

User interface changes

TBA

API changes

TBA

Data model changes

TBA

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇮Finland HeikkiY Oulu

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

Comments & Activities

Production build 0.69.0 2024