Argument 1 passed to OAuthUtils::getLoginUrl() must be an instance of Request, null given
Sometimes when i reload page, i get this error
Type error: Argument 1 passed to HWI\Bundle\OAuthBundle\Security\OAuthUtils::getLoginUrl() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Templating/Helper/OAuthHelper.php on line 72
http://prnt.sc/afyzo7
This is info from logs:
[2016-03-16 15:42:24] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Type error: Argument 1 passed to HWI\Bundle\OAuthBundle\Security\OAuthUtils::getLoginUrl() must be an instance of Symfony\Component\HttpFoundation\Request, null given, called in /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Templating/Helper/OAuthHelper.php on line 72" at /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Security/OAuthUtils.php line 146 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: Argument 1 passed to HWI\\Bundle\\OAuthBundle\\Security\\OAuthUtils::getLoginUrl() must be an instance of Symfony\\Component\\HttpFoundation\\Request, null given, called in /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Templating/Helper/OAuthHelper.php on line 72 at /home/dmac/www/projects/smm/vendor/hwi/oauth-bundle/Security/OAuthUtils.php:146)"} []
Code to render login links on the main page (copied from bundle)
<div>
{% block hwi_oauth_content %}
{% if error is defined and error %}
<span>{{ error }}</span>
{% endif %}
{% for owner in hwi_oauth_resource_owners() %}
<a href="{{ hwi_oauth_login_url(owner) }}">
{{ owner | trans({}, 'HWIOAuthBundle') }}
</a> <br />
{% endfor %}
{% endblock hwi_oauth_content %}
</div>
Do you know the cause of this error?
http://prnt.sc/afz4jv - additional info (symfony 3.0.3, php 7.0.4-6).
I can reproduce this error only for authenticated users.
It's produce same error for me.
I dig this issue a bit and here is the outcome For me (Symfony 3.0.4) issue happens only on first load, i.e. when no cache is available. Every subsequent request goes fine, unless I remove cache manually.
The problem is that RequestCompilerPass injects call setRequest() in hwi_oauth.templating.helper.oauth, passing @request or @request_stack as argument
For some reason, on first load RequestStack::getMasterRequest() (called in OAuthHelper::setRequest()) returns null, and so null is stored in OAuthHelper::$request, and then null is passed further to OAuthUtil, which triggers this issue.
Looks like problem is related to the services initialization order.
Calls order on first load:
- Kernel::handle()
- Kernel::boot()
- Kernel::initializeContainer()
- Container->get('cache_warmer')
- Container->get('twig') (for class
TemplateCacheWarmer) - Container->get('hwi_oauth.templating.helper.oauth')
I have the same error. Someone have solved this issue? Symfony 3.0.6
I've run into the same issue.
+1 same too
Same error here with php 5.6 and SF 2.8