From: Jorge P. de Morais Neto <jorge+list@disroot.org>
To: Floris Bruynooghe <flub@devork.be>, notmuch@notmuchmail.org
Subject: Re: New Python bindings (notmuch2 module) fail to exclude tags
Date: Sat, 21 Nov 2020 18:51:03 -0300 [thread overview]
Message-ID: <87h7pitm48.fsf@disroot.org> (raw)
In-Reply-To: <87zh3b99kb.fsf@powell.devork.be>
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
--
- <https://jorgemorais.gitlab.io/justice-for-rms/>
- 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?]]
next prev parent reply other threads:[~2020-11-21 21:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-20 15:54 New Python bindings (notmuch2 module) fail to exclude tags Jorge P. de Morais Neto
2020-11-20 18:02 ` David Bremner
2020-11-20 18:17 ` Floris Bruynooghe
2020-11-21 21:51 ` Jorge P. de Morais Neto [this message]
2020-11-24 22:33 ` Floris Bruynooghe
2020-11-25 11:07 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87h7pitm48.fsf@disroot.org \
--to=jorge+list@disroot.org \
--cc=flub@devork.be \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).