obsidian-dataview icon indicating copy to clipboard operation
obsidian-dataview copied to clipboard

Links to renamed/moved files don't update until file contents are edited

Open evanmtp opened this issue 3 years ago • 4 comments

What happened?

If a file is renamed or moved, any links to that file in a Dataview query will continue to point to the file's old path. If the link is followed, a new empty file with the same path will be created. The link is only updated when the content of the linked file is edited.

My expectation would be that the links in the Dataview query would be updated automatically to reflect changes to paths/filenames.

DQL

TASK 
WHERE due = date(today)
GROUP BY project

JS

No response

Dataview Version

0.4.22

Obsidian Version

0.13.19

OS

Windows

evanmtp avatar Jan 26 '22 09:01 evanmtp

Thanks for the report! We do update links to files that are renamed, it looks like though we've missed it for tasks or there's some bug somewhere in there. We'll take a look.

M-bot avatar Mar 05 '22 04:03 M-bot

@M-bot Here's a case to reproduce it:

View.md

// Type your search tags in the "search" array. Order doesn't matter.
let search = ['#context/online', '#prio/high'];
// Which folder to search in.
let folder = 'Tasks/Projects';
// ---
// Search algorithm.
let search_re = search.map(s => new RegExp('^' + s.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&') + '(?:\\/|$)'));
let next_tasks = [];
dv.pages('"' + folder + '" and ' + search.join(' and ')).forEach(p => {
	// Process all tasks in the current file to check if they match.
	let seen_sections = new Set();
	p.file.tasks.forEach(t => {
		// Only process the first incomplete task of each section.
		if (seen_sections.has(t.section.subpath) || t.completed) return;
		seen_sections.add(t.section.subpath);
		
		// Only add this task if it contains all search-tags.
		// NOTE: Supports nested tags, so "#foo" matches "#foo/bar",
		// and properly parses tags, so "#foo" won't match "#foos".
		if (search_re.every(re => t.tags.some(v => re.test(v)))) {
			next_tasks.push(t);
		}
	});
});
dv.taskList(next_tasks, true);

Tasks/Projects/Test Project 1.md

# Subproject 1

- [ ] Task 1 #context/online #prio/high
- [ ] Task 2 #context/online #prio/high 
- [ ] Task 3 #context/online #prio/high 

# Subproject 2

- [x] Task 2.1 #context/online #prio/high 
- [ ] Task 2.2 #context/online #prio/high 
- [ ] Task 2.3 #context/online #prio/high 

Now view View.md and then right-click on Test Project 1.md and rename it. The dataview query clearly re-runs (you can see it flicker), but the page title/links in the dataview aren't updated. It will still say the name Test Project 1.

The only way to achieve an update is to restart Obsidian, OR go into the renamed document and edit the actual text contents of it.

My guess why this is a bug:

  • Renaming a file doesn't change its size or modification time. Perhaps Dataview treats the file as "already cached" and skips the changes if we only rename it?

Arcitec avatar Jun 26 '22 01:06 Arcitec

There's a command to refresh views, can you check if that helps?

AB1908 avatar Jun 26 '22 10:06 AB1908

Hmm, file renames seem to update instantly in views for me; Dataview watches for file renames according to the Obsidian metadata-cache:rename event, and updates data there.

blacksmithgu avatar Jun 28 '22 04:06 blacksmithgu

Hello, sorry to come back to you so late. I currently go through older issues to see which are stale or already solved.

Due to missing feedback, I'll close the issue for now. If the problem still occurs for you, please comment on the issue with details on what is not working as expected and the requested information and I'll reopen your report.

s-blu avatar Dec 29 '22 19:12 s-blu

Hi, I stumbled upon this issue because I still have the same exact problem.

It seems that the file link is NOT updated when doing a TASK query, but IS updated when doing other kind of query, for example:

TABLE
file.tasks
WHERE file.tasks

l-ferrone avatar Apr 19 '24 12:04 l-ferrone