[GH-ISSUE #1015] Weird get_request() is None #862

Closed
opened 2026-02-27 11:13:59 +03:00 by kerem · 5 comments
Owner

Originally created by @gawel on GitHub (Feb 2, 2017).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/1015

Originally assigned to: @tonioo on GitHub.

Got this traceback (row mail from our production server):

Traceback:  

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  149.                     response = self.process_exception_by_middleware(e, request)

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  147.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/utils/decorators.py" in inner
  184.                     return func(*args, **kwargs)

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/reversion/revisions.py" in do_revision_context
  315.                 return func(*args, **kwargs)

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/reversion/revisions.py" in __exit__
  308.             self._context_manager.end()

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/reversion/revisions.py" in end
  202.                             db = self._db,

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/reversion/revisions.py" in save_revision
  516.                     versions = new_versions,

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send
  192.             response = receiver(signal=self, sender=sender, **named)

File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/modoboa/core/handlers.py" in post_revision_commit
  27.     current_user = get_request().user.username

Exception Type: AttributeError at /manager/admin/accounts/new/
Exception Value: 'NoneType' object has no attribute 'user'

We are using mod_wsgi without threads.

Originally created by @gawel on GitHub (Feb 2, 2017). Original GitHub issue: https://github.com/modoboa/modoboa/issues/1015 Originally assigned to: @tonioo on GitHub. Got this traceback (row mail from our production server): ``` Traceback: File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 149. response = self.process_exception_by_middleware(e, request) File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 147. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/utils/decorators.py" in inner 184. return func(*args, **kwargs) File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 23. return view_func(request, *args, **kwargs) File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 23. return view_func(request, *args, **kwargs) File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/reversion/revisions.py" in do_revision_context 315. return func(*args, **kwargs) File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/reversion/revisions.py" in __exit__ 308. self._context_manager.end() File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/reversion/revisions.py" in end 202. db = self._db, File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/reversion/revisions.py" in save_revision 516. versions = new_versions, File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py" in send 192. response = receiver(signal=self, sender=sender, **named) File "/var/www/modoboa/vtenv/local/lib/python2.7/site-packages/modoboa/core/handlers.py" in post_revision_commit 27. current_user = get_request().user.username Exception Type: AttributeError at /manager/admin/accounts/new/ Exception Value: 'NoneType' object has no attribute 'user' ``` We are using mod_wsgi without threads.
kerem 2026-02-27 11:13:59 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@kryskool commented on GitHub (Feb 10, 2017):

Hi @gawel

Which version of modoboa, apache ?

Regards,

<!-- gh-comment-id:278887965 --> @kryskool commented on GitHub (Feb 10, 2017): Hi @gawel Which version of modoboa, apache ? Regards,
Author
Owner

@gawel commented on GitHub (Feb 23, 2017):

Just got this again today.

I'm using modoboa 1.6.3 and waitress as server.

<!-- gh-comment-id:281956245 --> @gawel commented on GitHub (Feb 23, 2017): Just got this again today. I'm using modoboa 1.6.3 and waitress as server.
Author
Owner

@gawel commented on GitHub (Feb 23, 2017):

It seems like current_user is only used to log the revision...

So I guess the action is done (not aborted by this error) but the user get a traceback.

I think this stuff should be more fault tolerant. eg: if get_request() is None then log as user "unknown"

<!-- gh-comment-id:281957899 --> @gawel commented on GitHub (Feb 23, 2017): It seems like current_user is only used to log the revision... So I guess the action is done (not aborted by this error) but the user get a traceback. I think this stuff should be more fault tolerant. eg: if get_request() is None then log as user "unknown"
Author
Owner

@tonioo commented on GitHub (Feb 26, 2017):

The get_request() signal is used by other parts of the code but in this
case, it is just used to know the user performing the action.

The original trace you posted occured while creating a new account and
this action requires the current user to be authenticated... Could it be
a waitress issue?

On 23/02/2017 11:41, Gael Pasgrimaud wrote:

It seems like current_user is only used to log the revision...

So I guess the action is done (not aborted by this error) but the user
get a traceback.

I think this stuff should be more fault tolerant. eg: if get_request()
is None then log as user "unknown"


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/modoboa/modoboa/issues/1015#issuecomment-281957899,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAgc7pAQ1eTuQyYPpaRC2KsEoAxXLI3pks5rfWJ3gaJpZM4L1Fq-.

<!-- gh-comment-id:282543548 --> @tonioo commented on GitHub (Feb 26, 2017): The get_request() signal is used by other parts of the code but in this case, it is just used to know the user performing the action. The original trace you posted occured while creating a new account and this action requires the current user to be authenticated... Could it be a waitress issue? On 23/02/2017 11:41, Gael Pasgrimaud wrote: > > It seems like current_user is only used to log the revision... > > So I guess the action is done (not aborted by this error) but the user > get a traceback. > > I think this stuff should be more fault tolerant. eg: if get_request() > is None then log as user "unknown" > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > <https://github.com/modoboa/modoboa/issues/1015#issuecomment-281957899>, > or mute the thread > <https://github.com/notifications/unsubscribe-auth/AAgc7pAQ1eTuQyYPpaRC2KsEoAxXLI3pks5rfWJ3gaJpZM4L1Fq->. >
Author
Owner

@gawel commented on GitHub (Feb 26, 2017):

Yeah, maybe. I think it's more related to multithreaded servers.

github.com/modoboa/modoboa@8db5eefc0c/modoboa/lib/middleware.py (L56)

Since you use a singleton, what happens if a thread initialize a middleware (and didn't call process_request yet) but another thread is trying to access the request from the signal ?

Maybe creating a request_accessor by thread id can solve the issue

<!-- gh-comment-id:282546175 --> @gawel commented on GitHub (Feb 26, 2017): Yeah, maybe. I think it's more related to multithreaded servers. https://github.com/modoboa/modoboa/blob/8db5eefc0cb924f2b86c4e3b8636ff00684ef708/modoboa/lib/middleware.py#L56 Since you use a singleton, what happens if a thread initialize a middleware (and didn't call process_request yet) but another thread is trying to access the request from the signal ? Maybe creating a request_accessor by thread id can solve the issue
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#862
No description provided.