Stop putting the note title in your Dataview queries

Canonical version: Stop putting the note title in your Dataview queries.

Renaming a note in my vault could empty its lists. No error, no warning. When I went looking, 18 notes had already lost them.

The fix fits in two characters: [[]].

What went wrong

My Templater templates for Projects, Goals, Plans and Activities include Dataview Serializer queries that list related notes. Here's one from a project template:

<!-- QueryToSerialize: LIST FROM #type/idea AND **<%tp.file.title %>** SORT file.name ASC -->

When I create a note, Templater replaces that tag with the note's title. The query now contains something like **Teach Organization (Goal)** as plain text, frozen forever.

And that's the problem. Obsidian's "Automatically update internal links" setting rewrites links when you rename a note, but it skips links inside HTML comments. Dataview Serializer queries live in HTML comments (that's what keeps them invisible and portable). So after a rename, the query still points at the old name. The next serialization finds nothing and overwrites the list with an empty one.

Real cases from my vault:

  • A goal renamed from "Teach Organization (Goal)" to "Teach Organization and Productivity (Goal)". Its Plans and Projects lists went empty, and I didn't notice
  • Activities renamed from "Reading (Activity)" to "Read (Activity)", and "Running (Activity)" to "Run (Activity)"
  • People notes like "Danton", which became "Georges Danton"

In total, 18 renamed notes had queries pointing at their own old name.

The fix: [[]]

In Dataview, [[]] means "the current file". So the template line becomes:

<!-- QueryToSerialize: LIST FROM #type/idea AND [[]] SORT file.name ASC -->

It works with Dataview Serializer too, because the plugin passes the note's path to Dataview as the origin of the query. [[]] resolves to whatever the note is called right now. Rename it as often as you like; there's nothing to update.

Bonus: the template is simpler, since that line no longer needs Templater at all.

I tested it before touching 4,788 notes

Rewriting thousands of queries on a hunch? No way. First, I ran all 12,778 affected queries in Obsidian both ways (the old **Own Name** version and the [[]] version) and compared the results: 0 differences.

Then I migrated 4,788 notes (14,083 self-links) with a small Python script. It runs as a dry run by default and only touches the query comment lines. It lives in my vault at 50 Resources/53 Scripts/fix_query_self_links.py.

Want to do the same in your vault? Make a backup, then use a regex find and replace or a short script: in each note, swap any link to the note's own name for [[]], on the query comment lines only. And fix your templates first, or you'll be doing this again next month 😅

Regular Dataview queries too

The same advice applies to normal Dataview code blocks. Write FROM [[]] or use this.file.link (e.g., WHERE contains(file.outlinks, this.file.link)) instead of typing the note's name. Those blocks have the same rename problem, since Obsidian doesn't update links inside code blocks either. The difference: Dataview shows the empty result live instead of writing it into your note, so at least you can see it.

Making Dataview Serializer catch this

I'm the author of Dataview Serializer, and a bug that silently writes an empty list is the worst kind. So I've opened three issues to catch this whole class of problems:

  • Rewrite the query text when a note it references is renamed (#87)
  • Don't overwrite the output when a query references a note that doesn't exist (#88)
  • Add a "Validate all queries" command that finds stale references (#89)

None of them has shipped yet. Until they do, [[]] is the fix.

That's it for today! ✨

References


About Sébastien

Ready to get to the next level?

Found this valuable? Share it with someone who needs it.

Join 6,000+ readers. Get practical systems for knowledge & AI. Free.

Subscribe ✨

Free: Knowledge System Checklist

A clear roadmap to building your own knowledge system. Subscribe and get it straight to your inbox.

6,000+ readers. No spam. Unsubscribe anytime.

Subscribe