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 qF1TFWUIuF8zXgAA0tVLHw (envelope-from ) for ; Fri, 20 Nov 2020 18:18:13 +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 cAQvEWUIuF/pJgAAB5/wlQ (envelope-from ) for ; Fri, 20 Nov 2020 18:18:13 +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 22E74940539 for ; Fri, 20 Nov 2020 18:18:10 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 37AAE28C64; Fri, 20 Nov 2020 13:18:02 -0500 (EST) Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by mail.notmuchmail.org (Postfix) with ESMTPS id 3AB06270CC for ; Fri, 20 Nov 2020 13:17:59 -0500 (EST) Received: by mail-ej1-x633.google.com with SMTP id 7so14180180ejm.0 for ; Fri, 20 Nov 2020 10:17:59 -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=LdT+mRpMLAqk6TDQ0i9mXtmeNsT3ikIYURndbaeiOp8=; b=JF2XAc4/kJnDEI0y7x+oop9B6XK+6fvFINOqJmwzvwqnI6HG0KVbsad9EgeyzA9Nj7 0w+4u14e6tgNwa9YmdH/agIP4AzAh6m3QeLy+U/L5KK2ceccuCb7/5Qa1SsqsGR0wiQ9 Bd1g6gTiDT73LJumaOGvfExZ/sDuvzR+v3xGDZp83f6vsWQT3h+7F6t9zJnhtoi+NAFz w2Zu1QtkdzyErvnlFgFX0GXSzaRC33vF6ohDvTABSLRHltao642PFp49yMjf+Kttq72G 9tdVZHZ/2QjrtXtt8EhRkr1IRS+33zZL4C1F8uocdKGOaijS/CgVEWa9Cm/Ro20Z5sa/ t77g== 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=LdT+mRpMLAqk6TDQ0i9mXtmeNsT3ikIYURndbaeiOp8=; b=UgSEoGL+zdk/OIV02lrQ4vubaKdL34k03y6e5Ipl9PEXkjwgLQ52zXfKnC+1ej6dM5 SpvGi3pM4bVUPM6GfySErOObWrH/odo1/x9DUsg0gH0/XC4sG/q4DpMwomvyiJfWAeVY JRD532AGHgmKiepAeQ65t/jMH9FiCcQw050FNTQEXmnoLS86ZIwd3NgBbrO2z+2xRcbH Kf1tzVb8MatUWs5vnQV1P/tmI6RmMx7pgBSJD+uHs17OQHKKIm7ewyDNcl0Mga3vRjt1 cLFf1cF6TPGuMm37m127CUAegViUV80pGh+N5cAW+DMYhboAvfFHwDATVIfcwENsyr4q oaPA== X-Gm-Message-State: AOAM5329j+ihwMw6XKAkJFJ9t7+kiySBSNdEUrXTMiiAtx5Mfe51uYlZ WBFWPkrJn/OQhkEh3TfMRoO9E6OOED4= X-Google-Smtp-Source: ABdhPJxOqDMe4sfTQ0N5J84gE7cDRZyW9HXJ4IKYj+ApqNfL4RGp4gt62CM1vUDypgApERK8ecJfPA== X-Received: by 2002:a17:906:26c6:: with SMTP id u6mr35286453ejc.349.1605896277993; Fri, 20 Nov 2020 10:17:57 -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 q24sm1404122edw.66.2020.11.20.10.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 10:17:57 -0800 (PST) Sender: Floris Bruynooghe Received: (nullmailer pid 8544 invoked by uid 1000); Fri, 20 Nov 2020 18:17:56 -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: <87r1oohvm0.fsf@disroot.org> References: <87r1oohvm0.fsf@disroot.org> Date: Fri, 20 Nov 2020 19:17:56 +0100 Message-ID: <87zh3b99kb.fsf@powell.devork.be> MIME-Version: 1.0 Message-ID-Hash: UTWUK4FDLZHXHVBX2YRR5PDYHDDMCZLC X-Message-ID-Hash: UTWUK4FDLZHXHVBX2YRR5PDYHDDMCZLC 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=JF2XAc4/; 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: +qwvAO2dnyA9 Hi Jorge, On Fri 20 Nov 2020 at 12:54 -0300, Jorge P. de Morais Neto wrote: > Hi. I am trying to migrate my Python3 script to the new Python bindings > (notmuch2 module). However, I cannot obtain a count of messages > matching a query excluding messages that have an exclude tag. From the > command line: > $ notmuch count 'is:.bf_spam' > 0 > > The CLI command correctly counts zero messages having '.bf_spam' tag, > because all such messages also have the excluded 'spam' tag. But from > Python: > > $ python3 > Python 3.7.3 (default, Jul 25 2020, 13:03:44) > [GCC 8.3.0] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import notmuch2 >>>> nm_db=notmuch2.Database() >>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',)) > 379 >>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), omit_excluded=nm_db.EXCLUDE.FALSE) > 379 >>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), omit_excluded=nm_db.EXCLUDE.TRUE) > 379 >>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), omit_excluded=nm_db.EXCLUDE.ALL) > 379 >>>> nm_db.count_messages('is:.bf_spam', exclude_tags=('spam',), omit_excluded=nm_db.EXCLUDE.FLAG) > 379 Personally I find the description of these flags in notmuch.h not very clear and don't claim to understand them (this probably explains the really bad docstring, we should improve those). But I expected to at least see the EXCLUDE.TRUE one, the default, to work. 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, *, To experiment you could also raise the exception for NOTMUCH_STATUS_IGNORED, even though for the bindings to silently swallow this is probably the best (this is really the bindings being more limiting than the C lib, if this bothers ppl we could add another keyword arg to let this raise as well). While the above patch is probably good, I feel like it's clutching at straws and unlikely to solve your problem. Could you try to reproduce this in plain C or maybe even in pretend-plain-c by using the capi.lib.notmuch_* calls directly? Cheers, Floris