magento / community-features

Magento Features Development is an Initiative to Allows Community Memebers Join to Development of Magento Features
46 stars 18 forks source link

Module ordering for modules without parent dependencies should be loaded in a consistent manner #121

Open kirkmadera opened 5 years ago

kirkmadera commented 5 years ago

Summary

Module ordering for modules without parent dependencies should be loaded in a consistent manner. Currently, it is very random and can cause issues that are unrelated to changes made within a release, thus making them very hard to debug.

Examples

We have hit this twice in the last month. We inherited a codebase that does not correctly set module dependencies in most of its custom modules. Everything works correctly until something causes the module order in app/etc/config.php to change. Modules tend to get rearranged significantly with any small change.

Examples we ran into:

Proposed solution

While declaring dependencies in module.xml files is the correct fix, this is not always possible with inherited code. I think module loading could be less unreliable in this scenario if we added some consistent rules around loading modules without declared child dependencies.

I propose a ruleset similar to this:

  1. Determine dependency order based on declared dependencies in module.xml files.
  2. Where there is ambiguity and modules are at the same level in the dependency tree, load them in alphabetic order.
  3. All modules without child dependencies should load last in alphabetic order

Alphabetic ordering would prevent the random sort issues we are seeing. Modules could continue to incorrectly not have module dependencies declared but still have consistent behavior across releases except in the case where we specifically change a related module.

kirkmadera commented 5 years ago

Copied over from https://github.com/magento/magento2/issues/18296 based on comment from Magento team.

orlangur commented 5 years ago

@kirkmadera,

Currently, it is very random and can cause issues that are unrelated to changes made within a release, thus making them very hard to debug.

It means nothing but that modules are poorly written.

Having some rule to order modules does not solve any problem, just hides it, and problems may appear when you introduce new module or add new module dependency.

hostep commented 5 years ago

@orlangur: I've seen this happen with core Magento modules as well, the hidden dependency problem. It is sometimes revealed when one or multiple custom modules are installed which then shuffles the load order of core Magento modules.

I agree that putting the load order of modules in a fixed order will keep hiding dependency problems, but the other argument is that it will be more reproducible if such a problem is then discovered. Now when you report such a problem, the ticket is quickly closed because it can't be reproduced, because a clean Magento shop can have Magento modules in a different order then a shop with a bunch of custom modules.

kirkmadera commented 5 years ago

Poorly written modules is a real world problem that happens all the time through inherited code. This would make Magento feel much more stable for bad codebases.