addons icon indicating copy to clipboard operation
addons copied to clipboard

[Task]: Raise an exception when trying to save an ActivityLog without a user

Open diox opened this issue 1 year ago • 1 comments

Description

Since the beginning of time addons-server has had the following code when creating an activity log:

        user = kw.get('user', core.get_user())

        if not user:
            log.warning('Activity log called with no user: %s' % action.id)
            return

Which means that if we attempt to create an ActivityLog with no user, and there isn't any attached to the thread, it silently fails. A warning is emitted but the code goes through, except that it won't have recorded the activity log at all.

Inside the request/response cycle, this is fine, because we call core.set_user() in UserAndAddrMiddleware which is called early in the process. But in tasks and management commands, this doesn't happen, so if we forget to explicitly do that, we silently fail to record ActivityLog unless something else cause the thread to have one set. This is causing at least https://github.com/mozilla/addons/issues/2010.

We should consider hard raising an exception here, and fixing our code so that it doesn't happen.

Acceptance Criteria

  • [ ] Explicit exception raised instead of a warning in log_create() when there is no user
  • [ ] All code & tests fixed to accommodate for that change.

┆Issue is synchronized with this Jira Task

diox avatar May 23 '24 10:05 diox

We should consider if all tasks should be run under the TASK_USER automatically (is there a reason why we wouldn't want that to happen?)

eviljeff avatar May 23 '24 10:05 eviljeff