GNU bug report logs -
#75779
persist-defvar symbol bound before definition, causing data loss
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 75779 in the body.
You can then email your comments to 75779 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Thu, 23 Jan 2025 07:47:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Joseph Turner <joseph <at> breatheoutbreathe.in>:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org.
(Thu, 23 Jan 2025 07:47:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
This bug report was previously submitted as bug#75684, but it appears to
have been lost by the mailing list. Here it is again:
Variables defined with persist-defvar which have persisted values are
sometimes bound to their persisted values before the package is loaded.
persist-defvar then incorrectly sets the symbol's persist-default
property to its persisted value, which then causes the persist value to
sometimes be deleted.
The bug in the wild: https://github.com/alphapapa/activities.el/issues/109
I am able to reproduce this issue on Emacs 29.4:
--8<---------------cut here---------------start------------->8---
rm -rf /tmp/test-persist-issue/
mkdir /tmp/test-persist-issue
cat > /tmp/test-persist-issue/init.el <<EOF
(package-initialize)
(unless (package-installed-p 'test-persist-issue)
(package-vc-install "https://git.sr.ht/~breatheoutbreathein/test-persist-issue"))
EOF
emacs --init-directory=/tmp/test-persist-issue/
--8<---------------cut here---------------end--------------->8---
Wait for Emacs to install test-persist-issue.el and persist.el, then:
--8<---------------cut here---------------start------------->8---
(progn
(require 'test-persist-issue)
(setf test-persist-issue 'foo)
(persist-save 'test-persist-issue)
(kill-emacs))
--8<---------------cut here---------------end--------------->8---
/tmp/test-persist-issue/persist/test-persist-issue now exists as
expected. Now run:
--8<---------------cut here---------------start------------->8---
rm -rf /tmp/test-persist-issue/elpa/
emacs --init-directory=/tmp/test-persist-issue/
--8<---------------cut here---------------end--------------->8---
Wait for installation again, then evaluate:
--8<---------------cut here---------------start------------->8---
(progn
;; (persist-default 'test-persist-issue) ;; foo (should be nil)
(persist-save 'test-persist-issue))
--8<---------------cut here---------------end--------------->8---
The second time Emacs is opened, just before the call to persist-defvar
in activities.el, the test-persist-issue variable is already bound to
the persisted value, which results in the persisted value being
incorrectly set as the default.
Why is the persist variable bound before the persist-defvar form?
This example uses package-vc for the sake of reliable bug reproduction,
but the issue also exists with package.el, as in the original report.
Thank you!
Joseph
P.S. The linked git repo contains two files, both of which appear to be
necessary to reproduce the issue. For the sake of future bug
reproduction, I have attached both files to this email.
[test-persist-issue.el (application/emacs-lisp, attachment)]
[test-persist-issue-other-file.el (application/emacs-lisp, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Mon, 03 Feb 2025 00:10:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 75779 <at> debbugs.gnu.org (full text, mbox):
Ping
Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org> writes:
> This bug report was previously submitted as bug#75684, but it appears to
> have been lost by the mailing list. Here it is again:
>
> Variables defined with persist-defvar which have persisted values are
> sometimes bound to their persisted values before the package is loaded.
> persist-defvar then incorrectly sets the symbol's persist-default
> property to its persisted value, which then causes the persist value to
> sometimes be deleted.
>
> The bug in the wild: https://github.com/alphapapa/activities.el/issues/109
>
> I am able to reproduce this issue on Emacs 29.4:
>
> --8<---------------cut here---------------start------------->8---
> rm -rf /tmp/test-persist-issue/
> mkdir /tmp/test-persist-issue
> cat > /tmp/test-persist-issue/init.el <<EOF
> (package-initialize)
>
> (unless (package-installed-p 'test-persist-issue)
> (package-vc-install "https://git.sr.ht/~breatheoutbreathein/test-persist-issue"))
> EOF
>
> emacs --init-directory=/tmp/test-persist-issue/
> --8<---------------cut here---------------end--------------->8---
>
> Wait for Emacs to install test-persist-issue.el and persist.el, then:
>
> --8<---------------cut here---------------start------------->8---
> (progn
> (require 'test-persist-issue)
> (setf test-persist-issue 'foo)
> (persist-save 'test-persist-issue)
> (kill-emacs))
> --8<---------------cut here---------------end--------------->8---
>
> /tmp/test-persist-issue/persist/test-persist-issue now exists as
> expected. Now run:
>
> --8<---------------cut here---------------start------------->8---
> rm -rf /tmp/test-persist-issue/elpa/
> emacs --init-directory=/tmp/test-persist-issue/
> --8<---------------cut here---------------end--------------->8---
>
> Wait for installation again, then evaluate:
>
> --8<---------------cut here---------------start------------->8---
> (progn
> ;; (persist-default 'test-persist-issue) ;; foo (should be nil)
> (persist-save 'test-persist-issue))
> --8<---------------cut here---------------end--------------->8---
>
> The second time Emacs is opened, just before the call to persist-defvar
> in activities.el, the test-persist-issue variable is already bound to
> the persisted value, which results in the persisted value being
> incorrectly set as the default.
>
> Why is the persist variable bound before the persist-defvar form?
>
> This example uses package-vc for the sake of reliable bug reproduction,
> but the issue also exists with package.el, as in the original report.
>
> Thank you!
>
> Joseph
>
> P.S. The linked git repo contains two files, both of which appear to be
> necessary to reproduce the issue. For the sake of future bug
> reproduction, I have attached both files to this email.
>
> [2. application/emacs-lisp; test-persist-issue.el]...
>
> [3. application/emacs-lisp; test-persist-issue-other-file.el]...
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Sun, 31 Aug 2025 15:26:01 GMT)
Full text and
rfc822 format available.
Message #11 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
This bug is that the code expects defvar to always set the variable's value to INITVALUE, i.e. to behave as though evaluated using eval-defun or eval-last-sexp. If the persist variable already has a value when persist-defvar is evaluated, such as when a package is reloaded, then the persist-default value will be set to the variable's current value instead of INITVALUE.
Data loss can then occur if the variable's default value is persist-equal to the current value and persist-save is called.
The attached patchset fixes the bug by always setting the persist-default symbol property to the INITVALUE passed to persist-defvar. Test, updated docstring, and explanatory comments included and version bumped.
Thank you!
Joseph
[0002-persist.el-Bump-version.patch (text/x-diff, attachment)]
[0001-Fix-persist-default-prop-being-set-to-current-value.patch (text/x-diff, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Sun, 31 Aug 2025 15:26:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Wed, 03 Sep 2025 15:11:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 75779 <at> debbugs.gnu.org (full text, mbox):
Ping!
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Wed, 03 Sep 2025 15:12:01 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Thu, 11 Sep 2025 21:19:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 75779 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Ping please. This patch is a trivial solution to a quite serious bug.
Thank you!
Joseph
On September 3, 2025 5:10:20 PM GMT+02:00, Joseph Turner <joseph <at> breatheoutbreathe.in> wrote:
>Ping!
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Thu, 11 Sep 2025 21:20:01 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Sun, 21 Sep 2025 16:59:02 GMT)
Full text and
rfc822 format available.
Message #29 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Ping please!
于 2025年9月3日 UTC 15:10:20,Joseph Turner <joseph <at> breatheoutbreathe.in> 写道:
>Ping!
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Sun, 21 Sep 2025 16:59:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Tue, 30 Sep 2025 11:33:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 75779 <at> debbugs.gnu.org (full text, mbox):
Sorry for the delay, I have pushed the change. (I had also forgotten
that you are the maintainer of persist, so I allowed myself to be more
lenient in reviewing the patch).
Joseph Turner <joseph <at> breatheoutbreathe.in> writes:
> Ping please!
>
> 于 2025年9月3日 UTC 15:10:20,Joseph Turner <joseph <at> breatheoutbreathe.in> 写道:
>>Ping!
Reply sent
to
Joseph Turner <joseph <at> breatheoutbreathe.in>:
You have taken responsibility.
(Wed, 01 Oct 2025 06:24:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Joseph Turner <joseph <at> breatheoutbreathe.in>:
bug acknowledged by developer.
(Wed, 01 Oct 2025 06:24:01 GMT)
Full text and
rfc822 format available.
Message #40 received at 75779-done <at> debbugs.gnu.org (full text, mbox):
于 2025年9月30日 UTC 11:31:45,Philip Kaludercic <philipk <at> posteo.net> 写道:
>Sorry for the delay, I have pushed the change. (I had also forgotten
>that you are the maintainer of persist, so I allowed myself to be more
>lenient in reviewing the patch).
All good. Thank you for the review and merge!
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#75779; Package
emacs.
(Wed, 01 Oct 2025 06:25:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org.
(Wed, 29 Oct 2025 11:24:18 GMT)
Full text and
rfc822 format available.
This bug report was last modified 19 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.