From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 9C5F36DE0B00 for ; Sat, 29 Jul 2017 05:06:29 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.102 X-Spam-Level: X-Spam-Status: No, score=-0.102 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_FROM_12LTRDOM=0.01, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zu14uDtGO0Qk for ; Sat, 29 Jul 2017 05:06:25 -0700 (PDT) X-Greylist: delayed 444 seconds by postgrey-1.36 at arlo; Sat, 29 Jul 2017 05:06:25 PDT Received: from ewpettersson.se (ewpettersson.se [46.16.233.179]) by arlo.cworth.org (Postfix) with ESMTPS id 283036DE0A9A for ; Sat, 29 Jul 2017 05:06:25 -0700 (PDT) Received: from ewpettersson.se (ppp118-209-210-154.bras2.mel11.internode.on.net [118.209.210.154]) by ewpettersson.se (Postfix) with ESMTPSA id D46EE11A1B5C for ; Sat, 29 Jul 2017 13:58:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ewpettersson.se; s=mail; t=1501329536; bh=1IhlcXnbODFtxEfbj6J+RqAaVKZ8n8ZXSRAsGHgmYSI=; h=Date:From:To:Subject:From; b=TNJzRmI2asBzvr8wf6e4gPBhggzXVbN9QLEl3LL2ieKDPnhBd5EV085+wfk/vgSCi RXAnVidjoTKqxSHZj3dnS9U+FbRB8v//ldaFx9JXrQHIvtzUE30NRcN6fBD81VHtlB y8b536+J8s9Q1XKF7eDABtsBagrNssOTq/oWwGLk= Received: by ewpettersson.se (sSMTP sendmail emulation); Sat, 29 Jul 2017 21:58:50 +1000 Date: Sat, 29 Jul 2017 21:58:50 +1000 From: William Pettersson To: notmuch@notmuchmail.org Subject: Python/thaw/freeze: Different references to same message Message-ID: <20170729115850.ojg4uzalfyv7i64t@enigmas> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="tx4higfagq4pfuha" Content-Disposition: inline User-Agent: NeoMutt/20170428 (1.8.2) X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Jul 2017 12:06:29 -0000 --tx4higfagq4pfuha Content-Type: multipart/mixed; boundary="ubiqlrluu5ucfgsc" Content-Disposition: inline --ubiqlrluu5ucfgsc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hey, I've been trying to emulate something similar to what Ben Gamari shows in https://notmuchmail.org/pipermail/notmuch/2011/003976.html and I ran into an issue. That script (which admittedly is from 6 years ago) freezes messages before changing tags. But when changing tags, new searches are often run, returning some of the same results. It seems any changes on these "inner" messages are lost when the outer messages are thawed, and I'm guessing this is because the "inner" and "outer" messages reference different objects in memory which point to the same Xapian document. I've attached a short script which demonstrates this, to test it you need at least one message tagged with "this_is_my_test", but the script is fairly simple. Now If I'm correct in guessing the issue here, I can understand that it's not the sort of thing that is fun to fix, so I'm more looking to see if my understanding is right. In particular, I'm asking because clearly 6 years ago Ben's scripts worked, so maybe I'm just not understanding them/notmuch correctly. If I am right, then I'll just leave out the freezing/thawing. As it stands, I'm only adding ~5-10 emails at most each run (which is every 10 minutes) so performance when adding emails isn't (yet) an issue for me. Will --ubiqlrluu5ucfgsc Content-Type: text/x-python; charset=us-ascii Content-Disposition: attachment; filename="test_nm.py" import notmuch db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE) query_str = "tag:this_is_my_test" query1 = notmuch.Query(db, query_str) for msg in query1.search_messages(): msg.freeze() print "At start tags are %s" % ", ".join(msg.get_tags()) msg.add_tag("added_first") query2 = notmuch.Query(db, query_str) for msg2 in query2.search_messages(): msg2.freeze() msg2.add_tag("added_second") msg2.thaw() print "Inside inner loop tags are %s" % ", ".join(msg2.get_tags()) msg.thaw() print "At end tags are %s" % ", ".join(msg.get_tags()) msg.remove_tag("added_first") --ubiqlrluu5ucfgsc-- --tx4higfagq4pfuha Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE138IU9ak7nECo51G94VtKwkR42cFAll8eHUACgkQ94VtKwkR 42fgThAAhg/LIo0hecDMt9wVRhVNBHq02QuqODdgsgBgWyJxM/LSFJkSLtWIJArg VgZEFcVAYZFEQ3v9CUqwA4WIlw+ZIOSKCDVnaNx7Sv57yZfnz/gu27b8Aw3Uj07c 82z4LBA6urjnSKqNC1dohU7/LmCtYpgVOciBoW8k1c5z1Mt1pCqfY9bjxGwseBve DqsxLfiNaHooaUjdQyE1ljonv4P9tQ8MfoeNpwOg4Z0YkIO6h2Lje6IGhWkGU4Or vUBWAGN7jL5uIv60Ns44dhMD1D3g3GSbJuLtvv+njnMk2AWZHHZZgwnewq+YYEOP orO7OFd01SlESmoLrERVd/g1mGwaEWSqru9CbTx1MFq8nuqG3/rWG49W3P7ma4aV Zq/+O2TLBWKNoHbQ06c4MAk8Pb6Pa0f9wdxLmRXe3vKptcpAOSUTLGIZozNPZAop 0VUbK5r2xNQU4cSKZ4ImUO/mBfhfxOXzN0P5wurs7OqNEKHSId49yRnuZ6GduqEO ikYW5Zs/ehsdYlF9YQpwDwKFi/YmwaHfMuMOPcrU0vOsNksWswgu/wxd8/BOvz8g rTP0zAwFmTFr7rFlpZ9wPYJfgPSpeL+0vAU/q7OXbb7slNS3xreqPn2vRXOgyaUc 3V4GxXw8fBIES5VT4bR6l9yMeDOw01mZPq+Q6EEshACt0yosWjM= =a/DB -----END PGP SIGNATURE----- --tx4higfagq4pfuha--