Skip to content

SELECT from media_storage_file_storage when media DB storage is not in use or disabled #38116

Open
@ilnytskyi

Description

@ilnytskyi

Preconditions and environment

  • Any version
  • Disabled and never used media Db storage

Steps to reproduce

  1. Disable and never use DB media storage
  2. Make sure the table media_storage_file_storage does not exists
    image
  3. Allow nginx to fallback to pub/get.php to resolve image
  4. Access non existent image e.g. https://magento.local/media/wysiwyg/someImage.jpg

Expected result

  1. The code execution does not trigger queries to media_storage_file_storage table
  2. The user gets placeholder image without triggering media_storage_file_storage table
  3. Mysql service does not contain warning logs about accessing the table media_storage_file_storage
  4. Exceptions are logged in and not silently suppressed Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize
  5. Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize does not use disabled DB media storage

Actual result

  1. The request triggers the queries to media_storage_file_storage table
  2. Mysql service contains warning logs about accessing the table media_storage_file_storage that does not exists
  3. Exceptions are not logged and silently suppressed in Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize
  4. Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize does not uses disabled DB media storage

Additional information

The execution path according blackfire

PDOStatement::execute(select e.* from media_storage_file_storage as e where (filename = ?) and (directory = ?))
 Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize
 Magento\MediaStorage\App\Media\Interceptor::createLocalCopy
 Magento\MediaStorage\App\Media\Interceptor::launch
 Magento\Framework\App\Bootstrap::run
 run_init::pub/get.php

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/MediaStorage/Model/File/Storage/Synchronization.php#L57
The Magento\MediaStorage\Model\File\Storage\Synchronization::synchronize executes a this code:

 /** @var $storage Database */
        $storage = $this->storageFactory->create();
        try {
            $storage->loadByFilename($relativeFileName);
        } catch (\Exception $e) {
        }

The workaround can be to adjust nginx config, but still the code has to be refactored, as no warnings logged, and query is fired to non-existent table.

Release note

During accessing images via pub/get.php the select queries to media_storage_file_storage are not fired when DB media storage is disabled.

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: MediaStorageIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Progress: ready for devReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions