On #1462 I had the same issue. I updated to 0.27.0 as @pennersr said to me and now I am getting the following error.
File "/home/ubuntu/.envs/app/local/lib/python2.7/site-packages/allauth/socialaccount/templatetags/socialaccount.py", line 19, in render
request = template_context_value(context, 'request')
File "/home/ubuntu/.envs/app/local/lib/python2.7/site-packages/allauth/compat.py", line 43, in template_context_value
value = getattr(context, key)
AttributeError: 'Context' object has no attribute 'request'
It is a very similar error that the one I was getting in #1462. I am still using django 1.9.8. am I missing something? The strange thing is that in my local instance as well as in my staging instance the error does not appear.
I just downgrade my Django to 1.8.14 and It worked. I guess the problem happens with the compat.py file with django 1.9.
Thank you
Any news about this? I am getting the same error running some tests in another project; And I can not downgrade that one to Django 1.8.
Thank you
If you could put together a minimal sample project that demonstrates the problem, or perhaps a test case that exposes it, I can see what it takes to fix the issue... so far I have not experienced this problem myself.
@jlariza did you try running prod app with DEBUG=True ? In my case, I was trying to query on request.user after the user logged out which caused the allauth library to raise this exception in prod. The simple fix was to check request.user.is_authenticated()
I am closing this until we have something more substantial to go on...
@pennersr the error is raised by /socialaccount/templatetags/socialaccount.py so basically any view that uses the socialaccount template tags (like login and sign up) is raising it. I will try to reproduce the error in a small project. Thank you
Please do... if you have something reproducible I will be happy to have a look at it.
@pennersr I have been trying to reproduce it but i have not been able to, however i have an idea of why it is happening.
In socialaccounts.py you have something like:
class ProvidersMediaJSNode(template.Node):
def render(self, context):
# Before it was request = context['request'], so it used to raise a KeyError
request = template_context_value(context, 'request')
ret = '\n'.join([p.media_js(request)
for p in providers.registry.get_list(request)])
return ret
When there is an issue while rendering, the request key does not exist, so it raises an error. Originally it was a KeyError (like the title on this issue says) but it was changed later, so now it is raising an AttributeError:
AttributeError: 'Context' object has no attribute 'request'
This issue does not happen by itself, it happens when something else arises, but it shadows the original issue behind the raised exception here, making the original issue really hard to find.
I will post a way to reproduce it if i am able to, but it seems to be tricky to do it (already spent some time trying to do that).
What is going on with this error? Every time I have an internal server error on my app, it spits out dozens if not hundreds of these errors. You can see the entire source code of my application at my github.com/mekhami/fbwladder repo.
@cdvv7788 why did work on this disappear?
I know this is a closed issue, but I just wanted to add that I've been seeing this same issue.
If I've submitted a form and then try to re-submit another, or the same form on the page, it always results in a KeyError from allauth/socialaccount/templatetags/socialaccount.py line 18: request = context['request']. It seems to happen even on pages that don't load a login form.
I have django.template.context_processors.request included of course, and it's only an issue when submitting a form twice. It happens on regular admin pages and the admin page when there's been a POST from the action menu.
Same error on Django 1.11.16
Apologies, my TEMPLATES settings were being overridden.
For people who come here in future, check if you are using render_to_string method, which doesn't go through context processors. If you're doing so, pass the request to context manually
@string-areeb That is something to watch for although I have it happening on HttpResponseRedirect and admin actions.
Same issue
Django 2.2.3
I've got RequestContext object in 'context' variable at https://github.com/pennersr/django-allauth/blob/d34018a4ef40eb0c112c82672abeef402af7ee98/allauth/socialaccount/templatetags/socialaccount.py#L16
And it is an object with 'request' attribute, not dict value.
So request = context['request'] and request = context.get('request') do not work.
request = context.request is ok.
The view is called by from django.shortcuts import render method.
@pennersr,
Any ideas?
e.g.:
request = context.get('request')
if not request:
request = context.request
Most helpful comment
Same issue
Django 2.2.3
I've got RequestContext object in 'context' variable at https://github.com/pennersr/django-allauth/blob/d34018a4ef40eb0c112c82672abeef402af7ee98/allauth/socialaccount/templatetags/socialaccount.py#L16
And it is an object with 'request' attribute, not dict value.
So request = context['request'] and request = context.get('request') do not work.
request = context.requestis ok.The view is called by
from django.shortcuts import rendermethod.@pennersr,
Any ideas?
e.g.: