"Unexpected error" when accessing private file attached to unsaved node

Created on 3 August 2020, almost 4 years ago
Updated 10 July 2024, 8 days ago

Problem/Motivation

Download Count throws an error if an attached file's node is not yet saved.

The user-facing error is:

The website encountered an unexpected error. Please try again later.

The error log reports:

Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "type" violates not-null constraint DETAIL: Failing row contains (834, 42, 1, null, null, 10.128.62.121, Direct download, 1596425687).: 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); Array ( ) in Drupal\Core\Database\Connection->handleQueryException() (line 698 of web/core/lib/Drupal/Core/Database/Connection.php).

Steps to reproduce

  • Configure a node with an attachment and download count
  • Open the new node form and upload the attachment
  • Copy the attachment URL and visit it
  • Correct behaviour would be either access denied or file retrieval
  • Error behaviour is Drupal displays "The website encountered an unexpected error. Please try again later."

Proposed resolution

Download Count should identify that the file is not attached to an existing node, and not attempt to insert invalid data to the DB.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

2.2

Component

Code

Created by

πŸ‡³πŸ‡ΏNew Zealand xurizaemon Ōtepoti, Aotearoa 🏝

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

Comments & Activities

Not all content is available!

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

Production build 0.69.0 2024