Skip to content

Emulation dependency injected in the console commands through DI, tries to connect to database #76

@hostep

Description

@hostep

Hi!

There is a dependency injected in the console commands of this module that tries to connect to the database.
Since constructors of console commands are executed whenever bin/magento is ran, this causes an unneeded db connection attempt every single time.

Steps to reproduce:

  • Have a working Magento install (I'm using Magento 2.4.6-p1, but any version will probaby have the same issue)
  • Have elgentos/regenerate-catalog-urls version 0.3.5 installed
  • Change your app/etc/env.php file and use a database user that doesn't exist
  • Run bin/magento

Expected is no error mesages
But we are getting the following at the bottom:

In Abstract.php line 144:

  SQLSTATE[HY000] [1045] Access denied for user 'non-existing-user'@'localhost' (using password: YES)


In Abstract.php line 128:

  SQLSTATE[HY000] [1045] Access denied for user 'non-existing-user'@'localhost' (using password: YES)

After some quick playing around with the dependencies in the console commands of this module, it turns out that it's the dependency Magento\Store\Model\App\Emulation that causes the problem (either directly or through one of it's own dependencies, didn't check further). If I quickly comment out that Emulation dependency in the 3 console commands of this module, then we no longer get that error.

Solution is probably to inject Magento\Store\Model\App\Emulation as a Proxy, that should prevent a database connection to be made upon each bin/magento call.

(you might need magento/magento2#37424 as well, to fully test if this got fixed)

Thanks for considering this fix! 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions