Skip to content
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

avoid trying to load nonexistent DoctrineTransportFactory class #1373

Closed
wants to merge 1 commit into from

Conversation

craue
Copy link
Contributor

@craue craue commented Jun 21, 2021

This fixes symfony/symfony#41727.

@craue
Copy link
Contributor Author

craue commented Jun 21, 2021

This instead would also do:

- if (! class_exists(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class)) {
+ if (! class_exists(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class, false)) {

@ostrolucky
Copy link
Member

ostrolucky commented Jun 21, 2021

Build needs to be green. Please test if your second solution works in both scenarios, it's SA friendly

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jun 21, 2021

  • if (! class_exists(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class, false)) {

I'm not sure this would, as it would not try to actually load the class and would rely on class loading order.

@craue
Copy link
Contributor Author

craue commented Jun 21, 2021

I could only test if it's working in my scenario (to avoid the error), it does.

@nicolas-grekas
Copy link
Member

OK, then I confirm this 2nd patch would break the logic when the package is found in vendor.

@craue
Copy link
Contributor Author

craue commented Jun 21, 2021

Too bad. What about the failing SA then?

@ostrolucky
Copy link
Member

Closing here, as this is a broken BC on Symfony side. Doctrine-bundle shouldn't have to update the code just so it keeps working with next minor symfony version. Please fix BC layer on Symfony side.

@ostrolucky ostrolucky closed this Jun 22, 2021
@ostrolucky
Copy link
Member

Actually, just noticed code on symfony side didn't change since symfony 5.1, which is probably when we added class_exists, so it's our BC layer that was broken whole time

@ostrolucky ostrolucky reopened this Jun 22, 2021
Copy link
Member

@ostrolucky ostrolucky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One solution which should be better is reversing the conditions. Default to new transport factory. If it doesn't exist, use legacy one.

@craue
Copy link
Contributor Author

craue commented Jun 23, 2021

Like this?

- if (! class_exists(DoctrineTransportFactory::class)) {
-     // If symfony/messenger < 5.1
-     if (! class_exists(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class)) {
-         // Dont add the tag
-         return;
-     }
- 
-     $transportFactoryDefinition->setClass(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class);
- }
- 
- $transportFactoryDefinition->addTag('messenger.transport_factory');
+ if (class_exists(DoctrineTransportFactory::class)) {
+     $transportFactoryDefinition->addTag('messenger.transport_factory');
+ } elseif (class_exists(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class, false)) {
+     // symfony/messenger >= 5.1
+     $transportFactoryDefinition->setClass(\Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory::class);
+     $transportFactoryDefinition->addTag('messenger.transport_factory');
+ }

@craue
Copy link
Contributor Author

craue commented Jul 27, 2021

/ping

@ostrolucky
Copy link
Member

yes, but without false flag

@craue
Copy link
Contributor Author

craue commented Jul 27, 2021

yes, but without false flag

Without it, I'd get the initial error again.

@ostrolucky
Copy link
Member

I'm back to my first response: It's an issue on Symfony side. I've created symfony/symfony#42303. As for what you can do, you can call DebugClassLoader::disable() in your test case, or stop using symfony/phpunit-bridge, which enables it

@ostrolucky ostrolucky closed this Jul 28, 2021
@craue
Copy link
Contributor Author

craue commented Aug 12, 2021

Calling DebugClassLoader::disable() in my test case makes it pass but complain about

Remaining indirect deprecation notices (1)

  1x: Since symfony/messenger 5.1: The "Symfony\Component\Messenger\Transport\Doctrine\DoctrineTransportFactory"
class is deprecated, use "Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory" instead.
The Doctrine transport has been moved to package "symfony/doctrine-messenger" and will not be included by default
in 6.0. Run "composer require symfony/doctrine-messenger".

although I'm not actively using the messenger and cannot see a way to get rid of that deprecation notice.

@ostrolucky
Copy link
Member

see referenced issue. stop using symfony/symfony

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symfony 5.3: autoloader error with DoctrineTransportFactory
3 participants