From 8267e5c137484b2b403eefea0d5ef87bb4d17b8a Mon Sep 17 00:00:00 2001 From: danialmalik Date: Wed, 30 Sep 2020 10:43:40 +0500 Subject: [PATCH] :bug: Don't emit logout event for already anonymous user --- openedx/core/djangoapps/user_authn/views/logout.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/user_authn/views/logout.py b/openedx/core/djangoapps/user_authn/views/logout.py index cdf9d427f2b5..368636ee3e84 100644 --- a/openedx/core/djangoapps/user_authn/views/logout.py +++ b/openedx/core/djangoapps/user_authn/views/logout.py @@ -56,7 +56,6 @@ def dispatch(self, request, *args, **kwargs): # Get the list of authorized clients before we clear the session. self.oauth_client_ids = request.session.get(edx_oauth2_provider.constants.AUTHORIZED_CLIENTS_SESSION_KEY, []) - # if tests are giving Anonymous User objects event_data = {} if not request.user.is_anonymous: event_data = { @@ -67,7 +66,10 @@ def dispatch(self, request, *args, **kwargs): logout(request) - if request.user.is_anonymous: + # `event_data` will be empty if the user was anonymous even before + # the `logout` call. don't emit event if an anonymous user has hit + # the logout URL. + if request.user.is_anonymous and event_data: event_name = 'edx.user.logout' tracker.emit(event_name, event_data)