Files "lost" when moving to subfolder after unique constraint error (using dired)

I’m rearranging things. For example, I’m moving a bunch of files into a public/ subdirectory of my org-roam-directory. My process is that I launch dired while visiting the file I want to move, rename the file, and close the dired buffer. At this point I often make further edits to the file. The path of the file shows correctly as ~/org/roam/public/filename.org. When trying to save, however, I see the following:

Warning (org-roam): SQL constraint violation: “UNIQUE constraint failed: nodes.id”

It’s as if org-roam thinks the renamed file is a new file with the same ID. I then need to run org-roam-db-sync, open the file using find-file, make an edit, and save. Only then does org-roam know about it.

If I delete the buffer immediately after renaming, then reopen it before making edits, I don’t see the error. I’d rather not have to remember this, though. Is this expected behavior?

It sounds like a defect worth reporting, but I cannot reproduce it.

I can simply do the following, and no error; I can also see the file has moved correctly:

  1. org-roam-node-find and visit a file
  2. C-x C-f (find-file) and select the directory to open Dired
  3. Move the cursor to the file, and press R to rename (move) to a different subfolder under org-roam-directory
  4. switch-to-buffer and select the buffer that I just moved by renaming
  5. Edit the buffer and save

Interesting. I just restarted and ran through your exact steps and got the same UNIQUE constraint failed error when trying to save buffer.

(Doom) Emacs 27.2 on macOS latest.
org-version 9.6
org-roam-version 3615259 (is that normal?)

Maybe I’ll try a plain (non-Doom) configuration and see how it goes.

Thanks for the help.

I’ve tested this with a non-doom config and the error doesn’t occur when saving the moved file’s buffer. I should maybe mention it to the Doom folks. Debugging things like this is not something I’m great at :).

1 Like

I see. I’m using vanilla Emacs, so there seems to be something Doom does that causes the issue.

1 Like

Fwiw, I’m on Doom Emacs, and this has never been an issue for me.

I use doom’s rename-file function to great success.

Huh. You’re right, using rename-file avoids the issue. It’s a tiny bit less convenient than using dired but will work just fine. Thanks.