Problem/Motivation
Using Drupal 8.9 uploading files fails with an error
Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'type' cannot be null: INSERT INTO {download_count} (fid, uid, type, id, ip_address, referrer, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6);
Apparently in hook_entity_access, which is used in download_count_file_access (line 29 of download_count.module), the $operation == 'download' is also invoked during file upload. I do not find any information about this in the api documentation, except for one (Drupal 7) similar issue https://www.drupal.org/project/drupal/issues/2308347.
During upload the information of the referring entity is not known yet so the entity_type value is empty and we get the error.
Proposed resolution
Check if $references is empty before continuing to prevent the error: download_count.module
line 64: if (!empty($references)) {
line 105: }
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3191787-3.patch | 3.1 KB | mohit.bansal623 |
Comments
Comment #2
hansrossel commentedI suppose that the fact that the download operation is called during upload is rather a Drupal core issue and it is probably caused by the function valueCallback (line 60 of /core/modules/file/src/Element/ManagedFile.php) which is calling access('download')
and /core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php which is calling valueCallback in line 324 during upload
Comment #3
mohit.bansal623 commentedComment #4
tlwatson#3 works. I think it could be written more simply to continue/return if $references is empty, rather than wrapping everything in an 'if' statement.
Comment #6
usingsession commented@mohit.bansal623 thanks for patch.