-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Magento code generation bug, resulting in mails not sending! #14074
Comments
There seems to be nothing to fix here from Magento side. By convention, when class suffixed with Thoughts? |
After a quick analysis,
the problem is that The right way to go is to wrap problematic third party library in |
What convention are you talking about? A Magento convention?
If this is a common problem with most package, then might it just simply be the case that Magento has a faulty implementation?... Can you imagine if problems like these arrises in (for example) the order process instead of just the mails? Then no orders will be correctly saved without any alarm bells ringing, resulting in many missed commerce.
See the above, IMO the Magento generator should at least CHECK if the class it's trying to generate actually exists using the |
Well,
is literally saying that the class does not exist. By convention I mean that coding in Magento ecosystem you should know how classes like I don't see what can be fixed here on Magento side, as I described earlier https://github.com/Bogardo/Mailgun-Magento2 should not use non-Magento components like https://github.com/php-http/discovery directly, they should be wrapped in some custom factory or adapter in your module. |
@orlangur I truly hope you are joking right? So, because you guys have made up your own convention, the whole PHP ecosystem has to rewrite their code to support it for Magento?... I can tell you up front, not gonna happen. The bug is in the Magento autoloader BTW, if you guys build in a check if the class even exists before trying to make a factory out of it, the problem should never occur. Furthermore, https://github.com/Bogardo/Mailgun-Magento2 isn't using php-http/discovery directly as you can see in the composer.json. It is using the official mailgun/mailgun-php package, which on his turn depends on php-http/discovery. Last but not least,
It is already that smart that it knows it doesn't exist, then why on earth is it trying to make a factory out of it in the first place?! |
Then this package have to be wrapped in a proper class. The whole point is that client code should not depend on third party components directly.
That's how factory autogeneration works, please get familiar with documentation provided by me.
Please update issue description with expected result in terms of Magento autoloader behavior. Current behavior: when there is no class |
Yeah, that's how Magento does factory autogeneration, and it's incorrect and leads to unexpected bugs. That's why I opened this issue. Simply saying "oh don't use the word
Like said earlier, there is no exception that is being thrown, and if there is an exception thrown it get caught. However, in the adminhtml, you get a 200 OK when you send the mail, except the mail does not get sent (like I said earlier, its a silent error, hence the danger of leaving the autogenerator as-is)
Well if this is the case, then good luck wrapping all PHP packages with a class that has the word @orlangur t.b.h. do what you want with this issue, we got our application working again but be prepared to encounter more and more bugs like this to appear in the future until this is fixed. I only made this issue to inform you guys what is going on, already spend 2 days debugging trying to figure out what is wrong so I have no need for an endless "yes/no" discussion. |
Well, it would be much faster to just read the manual http://devdocs.magento.com/guides/v2.0/extension-dev-guide/factories.html#writing-factories prior to writing Magento code.
It is quite expectable to implement buggy software if you don't follow the best practices. Third party components are wrapped in classes for a reason and not just because Magento likes to have as much classes as possible. You faced exactly with the problem which is solved by such approach: upgradeability. Another problem solved is replaceability, you may replace third party component preserving just an interface.
This is clearly a bug in https://github.com/Bogardo/Mailgun-Magento2 and needs to be fixed. Emails are sent asynchronously in recommended setup thus you cannot see error in UI but of course logs should be monitored for errors.
Thanks for the quick feedback, closing this issue as per discussion. Feel free to reach me out anytime later if you come out with the way autogeneration may be improved for this case without breaking other important scenarios. |
I have briefly read the discussion and I've read the link @orlangur provided. If I understand this Magento conversion properly, then all code will break if I write: $bool = class_exists('FooFactory'); Is that really the intention? |
@Nyholm yes, that's how https://en.wikipedia.org/wiki/Fail-fast is supposed to work. Developer is quickly notified that he is referring to nonexistent As I understood the problem, some kind of feature detection is implemented with So, this particular logic need to be wrapped in order to make library compatible with Magento autogeneration. |
No. This is were you are wrong. It should not break anything. It should return
I understand that Magento has some sweet magic. But this is a PHP library. It does not care for any specific conventions etc etc in Symfony, Magento, Zend or any framework. If one would like to use a third party PHP library that contains the line |
@NickvdMeij, thank you for your report. |
Nope, see for example https://stackoverflow.com/a/1589227/8640867
The magic comes from a library calling
That's exactly why it is not safe to bring third party libraries into your client code without proper testing. Library should be either wrapped in your own classes or configured the way it plays well within Magento. For example, if https://github.com/php-http/discovery was configured in such a way that it does not perform such I'm open for any improvements into current Magento behavior. How you think autoloder can determine whether factory should be generated when |
... Im not sure what you are referring to.
There is not magic with calling
Wow, this seams a bit hostile to me. Telling people to not use other libraries is not the way you create "A Flexible, Open Source Commerce Platform" as you write in the heading of the website. I hear that you are open for improvements. That is awesome. Im afraid I know too little Magento to make any specific suggestions. I added a PR (#14085) with a unit test. I would suggest not to create classes when they are being autoloaded. The creation of classes should happen when the project is built (ie when the cache is warming up). That would also make it easier to deploy Magento on read-only filesystems. |
It triggers autoloading in some cases which obviously can throw exceptions.
That's not what I was saying. You should not use external classes directly in controllers/models/blocks etc but properly encapsulate them. So that you can upgrade or replace third party components easily afterwards. This is true even for PHP functions, like https://github.com/magento/magento2/blob/2.2-develop/lib/internal/Magento/Framework/Serialize/Serializer/Json.php. The fix is as simple as encapsulating code doing risky things
in your own class so that it does not trigger autoloading with code generation.
This would mean to remove proxies/factories autogeneration on demand feature which is pretty useful in developer mode.
This is exactly what |
Static calls and no way to configure component behavior is not a good choice when you implement Magento module. It would mean that you make your extension not extendable for others. Not just Magento core is quite flexible but also third party modules should be implemented keeping totally custom implementation in mind. So that you can install third party module and then slightly change its behavior with a custom implementation. |
Preconditions
Steps to reproduce
Expected result
Actual result
For some extra information see the following issues:
mailgun/mailgun-php#452
php-http/discovery#105
The text was updated successfully, but these errors were encountered: