From patchwork Sat Apr 27 11:12:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 1091907 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44rpDq58cdz9sB3 for ; Sat, 27 Apr 2019 21:12:59 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="hUriP+0C"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 44rpDq3D6HzDqZB for ; Sat, 27 Apr 2019 21:12:59 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 44rpDg2jFTzDq8F for ; Sat, 27 Apr 2019 21:12:51 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="hUriP+0C"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 44rpDg0pXkz9sCJ; Sat, 27 Apr 2019 21:12:51 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1556363571; bh=KUgnE1Bx4oKax5qXx63wDWH4Aa630W20Gv6iWX9Aygo=; h=From:To:Subject:Date:From; b=hUriP+0CID1/Wy7Td0nm8GntmUzvKMv8xqnjCgeZZhYYfWc3eNj6fxBWlGBOoKC0n 1N4foUiuNnn+1TdbGw+pAJulMsuRd6ccRfupZ1vK1USQvVTremW1ckFrtLkx2oPiqL PvLVrLXTE9I14tapS8xs3ChsDGpLl2QqMGQruZ+Xzw3qaFUbIqHUTSBpD/eZ1if3Ao fo5LFpshdQQovkheMVTsBtfXahly3oZi1+nPl0x+888yHymAhCWTOY9op5JXad6zmK cRdjIxGY87rqRT6Rs6dKZIocYAN3g9wRhN6csjV/a6gQJLYrg/hvOwJFoGAt4zfX44 vsTBbbcVm60uA== From: Jeremy Kerr To: patchwork@lists.ozlabs.org Subject: [PATCH] notifications: fix notification expiry when no user is associated Date: Sat, 27 Apr 2019 19:12:16 +0800 Message-Id: <20190427111216.1704-1-jk@ozlabs.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 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 --- patchwork/notifications.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/patchwork/notifications.py b/patchwork/notifications.py index a5f6423..571cff7 100644 --- a/patchwork/notifications.py +++ b/patchwork/notifications.py @@ -109,7 +109,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