3
MartinT
7y

Here's a story about why putting util functionality in a generic parent class is baaaad. So we run into a bug where an online shop module we develop causes a third party module to break the entire site until the session expires.

We track the bug down to the fact that the third party module has added some functionality to the part of the shop that deals with the cart and that functionality expects that one of the module's libraries is initialized. But as it turns out another of that module's libraries that is loaded earlier is fetching the cart and thus triggers our module which adds gifts to it.

Now, since we need a deeper integration with the cart to make gifts depend on the cart contents we call the part of it that now depends on the third party module's unloaded library.. So we think changing the order the third party libraries are loaded will fix the issue, only to discover the unloaded one is a child class of the first and the cart is fetched in the parent constructor. The parent of course then turns out to be a generic util class, inherited by all the module's libraries, so whatever order we load them in, the constructor is always called, so we had no other choice but to dynamically disable our module during the initialization of those libraries and then patch the updated cart contents into them after they've all been initialized.

At this point we get curious what that module's doing with the cart contents only to discover.. nothing. It's just that the parent class is full of utils and data fetching that the vendor reuses in all their modules..

Comments
Add Comment