Org-roam V2 / org-id ID link resolution problem

After upgrading to V2 and migrating all notes (adding an automatic ID property with org-id-get-create) and moving the Aliases inside the property drawer, I get some strange behaviour:

  • Updating the db runs fine, no errors. All files are cached
  • org-roam buffer with backlinks works
  • newly created notes can be linked and traversed to
  • org-roam find node works

However, all previously exisiting notes cannot be retrieved when clicked on links. Emacs throws an "Cannot find entry with ID: “XXXXXX” error, which is clearly an org-id error.

I thought org-roam somehow overrides org-id link functionality? Where does this happen in the code?
Or am I mistaken here and I need to rely on org-id-locations and add the full org-roam folder to the org-id-extra-files?

I have the same exact problem, for old notes I need to delete the id and create it again for the links to work.
Pretty manual but I have to manually change all the file links for id links anyways. I guess I should try to create some elisp to perform this automatically

It happened in the v1 in the function org-roam-link-follow-link:

(defun org-roam-link-follow-link (_path)
  (pcase-let ((`(,link-type ,loc ,desc ,mkr) (org-roam-link--get-location)))
       (org-goto-marker-or-bmk mkr)))))

It does not happen in v2 anymore:

(defun org-roam-link-follow-link (path)
  (pcase-let ((`(,id ,file ,pos) (org-roam-link-locate)))
    (org-id-goto id)))

So I guess one has to rely on org-id-locations. This could help find all the already existing relevant files:

(setq org-id-extra-files (find-lisp-find-files org-roam-directory "\.org$"))
1 Like

@S_Fabris @spicy

In addition to @mshevchuk’s suggestion, this function might also work to update the org-id-locations. Source here.

(org-id-update-id-locations (org-roam--list-all-files))

I have functions out of this principle:

(defun my/org-id-update-org-roam-files ()
  "Update Org-ID locations for all Org-roam files."
  (org-id-update-id-locations (org-roam--list-all-files)))

(defun my/org-id-update-id-current-file ()
  "Scan the current buffer for Org-ID locations and update them."
  (org-id-update-id-locations (list (buffer-file-name (current-buffer)))))

@nobiot’s is a better approach.

1 Like

@mshevchuk , @spicy @S_Fabris
Updated the wiki. Feel free to update it as you see fit, please.


(org-id-update-id-locations (org-roam--list-all-files))

This worked. Now all IDs are cached and work independently of org-roam. This adds a second cache of all links and creates redundancy. This is good and bad at the same time: Good, because links will always work. Bad because two caches/databases need to be maintained.

I wonder if it would be faster to use the org-roam db for inter-file linking for simplicity and only fall back on org-id if the notes are used without org-roam.

This is the opposite to simplicity from the developer’s perspective. The new function is simpler than the old one and Org-roam does not have to care about how links work instead relying on the built-in mechanism, which is arguably more robust because a special effort is dedicated to it by Org maintainers. What Org-roam could do and I’m almost positive will do is provide a way to automatically update org-id database during initialization and whenever a note is created.

1 Like

This is what V2 does from what I have seen. It uses org-id-get-create during the capture process, so the ID gets generated and cached in the Org-ID way.

You should not have had to update the ID locations for V1 org files, because the Org-ID cache would not have been influenced by going from Org-roam V1 to V2.

The only reasons I could think of why you had to do it are:

  1. You used to generate Org-ID manually, without using the org-id-get-create command, and other Org-ID commands.
  2. You moved Org-roam files/directory outside Emacs
1 Like