From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id ckeuJ+WLuV+4SwAA0tVLHw (envelope-from ) for ; Sat, 21 Nov 2020 21:51:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id KGwHI+WLuV83KwAAB5/wlQ (envelope-from ) for ; Sat, 21 Nov 2020 21:51:33 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (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 73223940484 for ; Sat, 21 Nov 2020 21:51:30 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 0D1CE28C8C; Sat, 21 Nov 2020 16:51:21 -0500 (EST) Received: from knopi.disroot.org (knopi.disroot.org [178.21.23.139]) by mail.notmuchmail.org (Postfix) with ESMTPS id 48A09203D7 for ; Sat, 21 Nov 2020 16:51:17 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id C7FF040058; Sat, 21 Nov 2020 22:51:14 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PxfLuYRe7zNd; Sat, 21 Nov 2020 22:51:13 +0100 (CET) From: Jorge P. de Morais Neto DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1605995473; bh=djVW995PPUlYMrQzLXAXyT8e8w6n0ir48QJRtcdjAUg=; h=From:To:Subject:In-Reply-To:References:Date; b=VfOxico4tLNeZNhdd3d5sGUS7enOydkMfUB7+/5G3P3Dx5v02RBt5noOr4M1AjeEs DrW2uBbQiiau7VOzeNMenRPHQK6c42seAcdzx2y5ZfmJ8fc8OSW3Q6bpE4y6F1CiNl hZ2Xe/WA9C+wdWmZbKgnCGir/sVxuIL5sts8Mkog4bsqxl+WcOZ2fJhjaTraWnr7LQ pnMpenojJKt03IJB65inqQRoji+6vxJNArseeIMkrSwbnlwIY7QiOGf+Sy7FmtZ4kP jSHsnAbPNB8Y/1+PA6TmsDIkz7EZLdf1LzKhXh8NScQ2v5zmI4R8a4csW5/K+yxHpZ s/17tKBA19eMQ== To: Floris Bruynooghe , notmuch@notmuchmail.org Subject: Re: New Python bindings (notmuch2 module) fail to exclude tags In-Reply-To: <87zh3b99kb.fsf@powell.devork.be> References: <87r1oohvm0.fsf@disroot.org> <87zh3b99kb.fsf@powell.devork.be> Mail-Followup-To: Floris Bruynooghe , notmuch@notmuchmail.org Date: Sat, 21 Nov 2020 18:51:03 -0300 Message-ID: <87h7pitm48.fsf@disroot.org> Mime-Version: 1.0 Message-ID-Hash: 5EQ4BHZ2XHYIYNLPMABJXYHUXPGVJKSH X-Message-ID-Hash: 5EQ4BHZ2XHYIYNLPMABJXYHUXPGVJKSH X-MailFrom: jorge+list@disroot.org 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 X-Spam-Score: 6.00 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=disroot.org header.s=mail header.b=VfOxico4; dmarc=fail reason="SPF not aligned (relaxed)" header.from=disroot.org (policy=quarantine); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Spam: Yes X-TUID: IfB6yYawvAiJ 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. After you apply my patch and also add the error checking, you could send me the combined patch, so I don't have to wait for the next release to get the desirable error checking. Regards -- - - If an email of mine arrives at your spam box, please notify me. - Please adopt free/libre formats like PDF, ODF, Org, LaTeX, Opus, WebM and 7z. - Free/libre software for Replicant, LineageOS and Android: https://f-droid.org - [[https://www.gnu.org/philosophy/free-sw.html][What is free software?]]