summaryrefslogtreecommitdiff
path: root/patchwork/notifications.py
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2019-04-27 19:12:16 +0800
committerDaniel Axtens <dja@axtens.net>2019-04-30 14:49:45 +1000
commitd0b79d9dee04aee13c8d64a193a7818f72eeca3b (patch)
tree7e65f73aa5bec3dfbaf5599689b8ca58b33e5a88 /patchwork/notifications.py
parentba0883c0fcab7630c64f1782a0d9eeaffa1ade99 (diff)
downloadpatchwork-d0b79d9dee04aee13c8d64a193a7818f72eeca3b.tar
patchwork-d0b79d9dee04aee13c8d64a193a7818f72eeca3b.tar.gz
notifications: fix notification expiry when no user is associated
It's possible that an EmailConfirmation object will have no associated user (eg, for email opt-out, which does not require a user object). In this case, we will see a NULL value for EmailConfirmation.user_id. However, having a NULL value appear in a SQL 'IN' clause will match every value. This means that once one of these null-user EmailConfirmations is present, we will never expire any non-active user accounts. This change adds a filter for a valid user_id when we query for active EmailConfirmation objects. This means we'll have a valid values set to use in the pending_confs set. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> [dja: fix pep8 issue] Signed-off-by: Daniel Axtens <dja@axtens.net>
Diffstat (limited to 'patchwork/notifications.py')
-rw-r--r--patchwork/notifications.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/patchwork/notifications.py b/patchwork/notifications.py
index 7be30f0..111feb2 100644
--- a/patchwork/notifications.py
+++ b/patchwork/notifications.py
@@ -96,7 +96,8 @@ def expire_notifications():
EmailConfirmation.objects.filter(q).delete()
# remove inactive users with no pending confirmation
- pending_confs = EmailConfirmation.objects.values('user')
+ pending_confs = (EmailConfirmation.objects
+ .filter(user__isnull=False).values('user'))
users = User.objects.filter(is_active=False).exclude(id__in=pending_confs)
# delete users