Django message framework called with None
|Reported by:||merb||Owned by:||Denis Cornehl|
|Cc:||c.schmitt@…||Triage Stage:||Ready for checkin|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently, this is a very small bug and i don't now the first occurance, since i first used the message framework at the last evening.
I used Django 1.6 and installed everything. I put the Message Framework into the middleware, the context preprocessor and the INSTALLED APPS.
And then I did something which happend, cause i was very sleepy.
I made a generic.FormView like this:
class CreateUserView(generic.FormView): template_name = 'envisia_backup/create_user.html' form_class = UserForm def get_success_url(self): return reverse('envisia:index') def form_valid(self, form): data = form.cleaned_data user = User.objects.create(**data) user.is_staff = True user.is_superuser = True user.save() messages.success(request, 'User erfolgreich erstellt!') return HttpResponseRedirect(self.get_success_url())
Since I was sleepy I really didn't know where the mistake was.
The error message always was that the message framework wasn't installed and I should put it in the middleware and in the INSTALLED_APPS.
Why did this happen? Currently it happend cause I called messages.success with None.
request wasn't defined. so it was None. It took a while since I found the error since I never got a correct error message.
Currently the fix would be really simple. But I don't want to make a patch until know since I don't know if it is wished that the messages framework should make a assert if we call it with a Request object or not.
If it is wished that the message framework could only be called with a request object, than i would make a patch with a corresponding test. But only if this is really wished.
Change History (7)
comment:1 Changed 3 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Unreviewed → Accepted|