From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id anDBEFaKvV86bgAA0tVLHw (envelope-from ) for ; Tue, 24 Nov 2020 22:33:58 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id CO0wDFaKvV+WDQAAbx9fmQ (envelope-from ) for ; Tue, 24 Nov 2020 22:33:58 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 76C579404D3 for ; Tue, 24 Nov 2020 22:33:50 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 63B9228CA4; Tue, 24 Nov 2020 17:33:42 -0500 (EST) Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by mail.notmuchmail.org (Postfix) with ESMTPS id D4D1628CA1 for ; Tue, 24 Nov 2020 17:33:38 -0500 (EST) Received: by mail-ed1-x535.google.com with SMTP id y4so481637edy.5 for ; Tue, 24 Nov 2020 14:33:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:in-reply-to:references:date:message-id :mime-version; bh=joPtopJL8aSBlk94+zjarrh1DNQtP96q+Mz3WjvtoBI=; b=si+6I+fcPWY5t/cuCLBoKZgWEeTPo2DNP2aluSWzw5uoiZdZWyKMoYKajK2o8TV6e3 j/Y79j4HWiAfx9ciccuAn6g02QGhhTZsoW2SwC+Bh5cW0TuJBe2xKw0PUW0T7nZ3wF/k 9kjF5D1/x1LW9jhsKuFiXvAMk74nWjwDJ303Jpa1BVC+t++0E+CRuc6IYf7LPc+YXCTN RaXBc9e9GpKYZyE1zlwcJv4lk5q8nLYLQucLd1Ga/BfvMVd0YXI4DZ0UkfZg86dGAq/e +y/f+GuJlwByLTx4RBFRERTRVcODQrDl79itMaAclFPJ1IBx5O0F2WeGElSAjntbWbWk EaMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:in-reply-to:references :date:message-id:mime-version; bh=joPtopJL8aSBlk94+zjarrh1DNQtP96q+Mz3WjvtoBI=; b=gBVMg9SA+HUP+6zKXKT7fPhddGvdYH9zyYMUGXVDcJ7CD2gYRl58IvGAP9tsll87s5 A8ZaEnkPmgKLZGhZ04CkCiwnTNCBmaV6NItO+sVc4L1zkYPdJNICI24wk4b37Y62jmCc TLCZoR1M2asd5ViUxHg7BC/hPkK1YY/AsvmlP+Un0UgN5qLyQ3AY07DwY3wPdZzLCfbe h9ovvF7ABThZPjYwHFjWdbCsJuzb13nN7mQ0FbhSnJ+ZfbKxkfzDQjBtEbIdflaRTrT7 X4mXuDYManRp/NbfXWloDHC4Nv3x2OPDCsc0/W8tq1I/1+nDfaj2yZjc/VvP2QJTAAOe a6Dw== X-Gm-Message-State: AOAM530nY3W8ni+fJVlE1UxwwK9XWcR+6QimfOGW/Tj76GV+e6x0O01c KZbUPK9zDSseYH17c0xtRRU= X-Google-Smtp-Source: ABdhPJytrIFeRo9JVK5BFCImejkEsjFb4F7dL9VtWrrVh66dxL9Ef4vaolDBpe6uW+qIjwfppXjSOQ== X-Received: by 2002:a50:d681:: with SMTP id r1mr698219edi.290.1606257216066; Tue, 24 Nov 2020 14:33:36 -0800 (PST) Received: from powell.devork.be (2a02-8388-8480-1180-4c18-fc69-8d8c-22b5.cable.dynamic.v6.surfer.at. [2a02:8388:8480:1180:4c18:fc69:8d8c:22b5]) by smtp.gmail.com with ESMTPSA id o3sm132218edj.41.2020.11.24.14.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 14:33:35 -0800 (PST) Sender: Floris Bruynooghe Received: (nullmailer pid 132700 invoked by uid 1000); Tue, 24 Nov 2020 22:33:33 -0000 From: Floris Bruynooghe To: "Jorge P. de Morais Neto" , notmuch@notmuchmail.org Subject: Re: New Python bindings (notmuch2 module) fail to exclude tags In-Reply-To: <87h7pitm48.fsf@disroot.org> References: <87r1oohvm0.fsf@disroot.org> <87zh3b99kb.fsf@powell.devork.be> <87h7pitm48.fsf@disroot.org> Date: Tue, 24 Nov 2020 23:33:33 +0100 Message-ID: <87y2iqpepu.fsf@powell.devork.be> MIME-Version: 1.0 Message-ID-Hash: HRUVSH36OFMVMTFLG73GDDHD3MPJVFO4 X-Message-ID-Hash: HRUVSH36OFMVMTFLG73GDDHD3MPJVFO4 X-MailFrom: floris.bruynooghe@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Scanner: ns3122888.ip-94-23-21.eu Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=si+6I+fc; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam-Score: -0.01 X-TUID: v/k1VwfmLM5l Hi All, On Sat 21 Nov 2020 at 18:51 -0300, Jorge P. de Morais Neto wrote: > Hi Floris. > > Em [2020-11-20 sex 19:17:56+0100], Floris Bruynooghe escreveu: > >> Looking at the implementation I don't seem much that could have gone >> wrong. However I did notice the bindings fail to check the return code >> in one call where it probably should, you could try with this patch? >> >> diff --git a/bindings/python-cffi/notmuch2/_database.py b/bindings/python-cffi/notmuch2/_database.py >> index 5ab0f20a..5dbfe68e 100644 >> --- a/bindings/python-cffi/notmuch2/_database.py >> +++ b/bindings/python-cffi/notmuch2/_database.py >> @@ -579,7 +579,10 @@ class Database(base.NotmuchObject): >> for tag in exclude_tags: >> if isinstance(tag, str): >> tag = str.encode('utf-8') >> - capi.lib.notmuch_query_add_tag_exclude(query_p, tag) >> + ret = capi.lib.notmuch_query_add_tag_exclude(query_p, tag) >> + if ret not in [capi.lib.NOTMUCH_STATUS_SUCCESS, >> + capi.lib.NOTMUCH_STATUS_IGNORED]: >> + raise errors.NotmuchError(ret) >> return querymod.Query(self, query_p) >> >> def messages(self, query, *, >> > After applying your patch, the call to nm_db.count_messages() fails: > AttributeError: cffi library 'notmuch2._capi' has no function, constant or global variable named 'NOTMUCH_STATUS_IGNORED' > > However, I then found the bug. The patch below fixes it. > > $ diff -u notmuch2-orig/_database.py notmuch2/_database.py > --- notmuch2-orig/_database.py 2020-11-21 18:02:17.560240619 -0300 > +++ notmuch2/_database.py 2020-11-21 18:43:44.827879141 -0300 > @@ -578,7 +578,7 @@ > if exclude_tags is not None: > for tag in exclude_tags: > if isinstance(tag, str): > - tag = str.encode('utf-8') > + tag = tag.encode('utf-8') > capi.lib.notmuch_query_add_tag_exclude(query_p, tag) > return querymod.Query(self, query_p) > > > However, I think you should *also* add the error checking. The only > reason my patch omits error checking is that I don't know how to define > capi.lib.NOTMUCH_STATUS_IGNORED. Yup, that was missing from _build.py so wouldn't have been available. Before fixing this I tried to write a test, but I don't know if this behaves correctly: I have a database with 3 messages organised in 2 threads and the following tags: msg1: all +- msg3: all, spam msg2: all I query '*', so all messages with exclude_tags=['spam']. Querying this with various flags gives me: NOTMUCH_EXCLUDE_TRUE: 2 messages, what I expect NOTMUCH_EXCLUDE_ALL: 2 messages, what I expect NOTMUCH_EXCLUDE_FLAG: 2 messages, I expected 3 NOTMUCH_EXCLUDE_FLASE: 2 messages, I expected 3 Did I misunderstand the docs? Are these results correct? Cheers, Floris