Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task path is not updated after note has been renamed #2548

Open
kim-fehl opened this issue Mar 18, 2025 · 12 comments
Open

Task path is not updated after note has been renamed #2548

kim-fehl opened this issue Mar 18, 2025 · 12 comments
Labels
bug Something isn't working.

Comments

@kim-fehl
Copy link

What happened?

I use dataview objects in Templater code.
This code snippet copies all the tasks with a scheduled date into the daily note, adding a link to a project note where these tasks belong to.
When the project note (containing the task) is renamed, task.path still contains original note name.

Probably has to do with this issue

DQL

No response

JS

<%*
const targetDate = tp.date.now("YYYY-MM-DD");
const dv = this.app.plugins.plugins["dataview"].api;

// Query all tasks in the vault
const scheduled_tasks = dv.pages().file.tasks
  .where(t => !t.completed && t.text.includes(`⏳ ${targetDate}`));

if (scheduled_tasks.length != 0) {
  scheduled_tasks.forEach(task => {
    // Extract the note title from the task's file path:
    let noteTitle = task.path.split("/").pop().replace(".md", "");
    // Create markdown checkbox format for each task, using the note title in the link.
    tR += `- [ ] ${task.text.replace(/\\s*${targetDate}/, "").trim()} [[${task.path}|🗂️ ${noteTitle}]]\n`;
  });
}
%>

Dataview Version

0.5.67

Obsidian Version

1.8.9

OS

Linux

@kim-fehl kim-fehl added the bug Something isn't working. label Mar 18, 2025
@holroy
Copy link
Collaborator

holroy commented Mar 18, 2025

After a template has been executed, it is considered static text, and you've lost any lookup of any part which was used in the template.

In other words, when you insert this template, and it uses Dataview to produce the output, you loose the link to the Dataview query, and all links and other text are just normal text, which will follow the normal rules if you rename or move any files related to that text.

So I'm not sure, what you're considering to be the bug here? Is it just a misconception from your part, that the template would be re-evaluated every now and then?

@kim-fehl
Copy link
Author

@holroy, I understand that Templater produces its output once and it remains static. Below I show that renaming the project note before Templater invocation leads to incorrect paths obtained via Dataview. I thought maybe it is a caching issue, but 10 minutes after renaming the bug is still there. Here's the video:

Image

Some of my settings:

Image

Image

@claremacrae
Copy link

I was curious so had a look.

I'm finding it hard to tell from the video what exactly the bug is.

Is there a simpler workaround with fewer moving parts? Like, assuming it really is a dataview issue, it should be possible to provide a minimal reproduction that demonstrates the problem with just a Dataview script.

Otherwise, how can you be sure it's not a Templater issue?

@kim-fehl
Copy link
Author

@claremacrae I'm sorry I didn't bother to make a minimal reproduction in the first place. Here's the one, showing that the issue persists without Templater:

const all_tasks = dv.pages('"DataView Bug/Test Projects"').file.tasks;

all_tasks.forEach(task => {
    let noteTitle = task.path.split("/").pop().replace(".md", "");
    dv.paragraph(`- [ ] ${task.text} [[${task.path}|🗂️ ${noteTitle}]]`);
});

Image

@claremacrae
Copy link

Thanks - that's a lot simpler.

I think that dataview has some settings to control how often it updates its results. I wonder if that could be affecting the behaviour?

@kim-fehl
Copy link
Author

@claremacrae After three hours, it's still the same. Looking at the source code, I see that .path property is derived from the .linkproperty. I tried to used it instead -- the bug is till here. I think you are right, it is likely an indexing/caching issue, as this source file reads, "Renames do not set off the metadata cache" and handles them separately.

@claremacrae
Copy link

Good find.

This sounds like the sort of thing that might have been reported before then.

Maybe earlier reports include workarounds?

@kim-fehl
Copy link
Author

@claremacrae Yes, in the issue I have linked earlier there is a workaround relying on Obsidian's own cache, not the DataView index.

@claremacrae
Copy link

Thank you.
So what was the purpose of creating a duplicate bug report then?

@claremacrae
Copy link

Ah, maybe it was only simplifying the reproduction that revealed whether you are encountering the same issue as earlier????

What do you think, is it now the same as the earlier issue? Would the fix for the earlier issue fix this one?

@holroy
Copy link
Collaborator

holroy commented Mar 20, 2025

They're not the same as far as I can see. The other issue is more related to changing the name of the file you're currently viewing, and how dataview handles that.

This issue seems to be more an issue related to how the data used in a query had been invalidated by a rename operation without Dataview detecting the rename. This is, and will be an issue, when we rely on the cache to get data from.

I've not looked into which cache has been invalidated, and whether this needs to be handled by dataview or obsidian. That is whether there should be some propagation related to the rename event somehow.

@claremacrae, do you have (or have had) any similar issue related to queries relying on the {{query.file.path}} variable and renaming of that file?

@claremacrae
Copy link

Great stuff - thanks @holroy.

Funnily enough I did something in this area in Tasks recently.

This is the one specific commit:

obsidian-tasks-group/obsidian-tasks@5fc9fba

Here's the latest code, after a bunch of refactoring:

https://github.com/obsidian-tasks-group/obsidian-tasks/blob/84ff5070059ff4c99cbe61f5e3492f551cbcbec9/src/Renderer/QueryRenderer.ts#L152-L176

Code is MIT - free free to use...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

3 participants