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)))
    ...
      ("id"
       (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."
  (interactive)
  (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."
  (interactive)
  (org-id-update-id-locations (list (buffer-file-name (current-buffer)))))
5 Likes

@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.

@nobiot

(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

I’ve been trying to figure out why I’m getting errors when I run @jethro and @d12frosted 's conversion script, and after finding this thread I realize it’s because I’ve done both 1. and 2. above.

  1. I have had capture templates that create file-level ID properties for while. Once I learned that org-roam v2 was going to make use of them, I started including them in all my new notes, but now I realize that org-id was unaware of them.
  2. In order to achieve my desire to have some org-roam files of a non-work nature only on my personal laptop, some org-roam files of a work nature only on my work laptop, and a third category of files that are useful both at work and at home, I moved files around and into 3 different repos, thinking all I needed to do was re-synch the Roam DB and I would be good. But I guess I left org-id out of the loop, so it was missing all those changes too.

Hi All, I’m trying to follow this along and running into an error when setting the variable - (setq org-id-extra-files (find-lisp-find-files org-roam-directory "\.org$")) . Specifically - (void-function find-lisp-find-files). Is this a known issue? Trying to find the find-lisp-find-files function seems to result in an error on this end, am I missing a package? Is there a way around that? I’m running Doom emacs if that helps.

It’s an old built-in library so you should have it installed in your Emacs. You can check it by looking for find-lisp-find-dired (it’s flagged as autoload so you can see it before loading the library).

Require or load-library find-lisp. You should see the function you are looking for.

Alternatively, you could try directory-files-recursively. Refer below.

SlackExchange answer

Edit: (2019) As mentioned in the answer by @mingwei-zhang and the comment by @xiaobing, find-lisp-find-files from find-lisp and directory-files-recursively also provides this functionality. However, please note in these cases the file name argument is a (greedy) regex. So something like (directory-files-recursively "~/my-dir" "org") will give you all Org files including backup files ( *.org~ ). To include only *.org files, you may use (directory-files-recursively "~/my-dir" "org$") .

thank you - this worked perfectly!!

1 Like

Thanks very much for the solution, Nobiot! For those looking at this past Dec 28 2021, the function org-roam--list-all-files is now org-roam-list-files.

1 Like

Think I had the same problem. Roam worked fine but exporting to html complained about missing IDs. Running org-roam-update-org-id-locations helped.

Also hi.