Circular reference detected for Drupal::service('url_generator')
I'm having issues debugging a php error that is only thrown during behat testing. If I try to load url_generator service during behat step definition I'm getting this error and the tests are ultimately failing.
Circular reference detected for service "url_generator", path: "url_generator". (Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException)
I was able to get all other services service I tried, looks like url_generator is the only exception. If I check:
$c = \Drupal::genContainer();
$c->hasService('url_generator');
=> bool(true)
$c->initialized('url_generator');
=> bool(false)
$c->get('url_generator');
=> Circular reference detected for service "url_generator", path: "url_generator". (Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException)
This error only started after I've updated to php8.1. I can not even reproduce if I run it within drush php console (I can get url_generator service normally).
The other url_generator service issue I see during behat execution is:
Type error: Drupal\Core\Routing\UrlGenerator::setContext(): Argument #1 ($context) must be of type Symfony\Component\Routing\RequestContext, null given (Behat\Testwork\Call\Exception\FatalThrowableError)
They are probably related somehow, not sure.
Any idea where could the error be?
That should be fixed with the latest Drupal driver version
@Berdir Thanks for response. I'll test it out
After php8.1 update faced the same. Updating drupal/drupal-extension with all dependencies solved the problem