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

Metadata calculated from inline DQL or DVJS queries is always unbound to the page #2509

Open
iredelmeier opened this issue Jan 17, 2025 · 1 comment
Labels
bug Something isn't working.

Comments

@iredelmeier
Copy link

What happened?

It seems that whenever metadata is calculated inline queries leveraging this (DQL) or dv.current() (DVJS - either directly or through code supplied through dv.view) aren't bound to the original page's context.

For example, given:

// view.js
return dv.current().foo
%% foo.md %%
foo:: hello
dql:: `= this.foo`
dvjs:: `$= dv.current().foo`
dvjsView: `$= await dv.view('view.js')'
%% bar.md %%
## DQL

```dataview
TABLE WITHOUT ID
	file.name,
	file.path,
	foo,
	dql,
	dvjs,
	dvjsView,
WHERE
	file.name = this.file.name
OR
	file.name = `"foo"`
```

## DVJS

```dataviewjs
const pages = [dv.current(), dv.page('foo')];

dv.table(
	['path', 'foo', 'dql', 'dvjs', 'dvjsView'],
	pages.map(page => [page.file.path, page.foo, page.dql, page.dvjs, page.dvjsView])
)
```

The file with the main queries will render as:

A DQL and DVJS table, both with the same incorrectly calculated metadata

Based on the docs and previous discussion, it seems like this is expected to (and used to!) at least work when the inline query used as a view and/or the main query used JS.

However, with #170 still open, maybe it actually isn't expected to work at all? It definitely makes sense that the implementation might be difficult and not necessarily worth either the effort or potential performance hit. I'm happy to submit a quick PR updating the docs based on this assumption!

DQL

No response

JS

Dataview Version

0.5.67

Obsidian Version

1.7.7

OS

MacOS

@iredelmeier iredelmeier added the bug Something isn't working. label Jan 17, 2025
@holroy
Copy link
Contributor

holroy commented Jan 23, 2025

When you use code like that, you don't set the inline field to the result value of the query, but rather to the actual query it self. This means if you later on try to get the inline field value, you'll get the query instead, and it's evaluated in the local context, which may or may not work.

This is not a bug, but more of a feature on how the inline fields have been implemented when you use them in combinations with inline queries. So it's not to be expected to work, unless the query make sense in every context you evaluate it.

So for example you could potentially use something:: `= [[foo]].anotherValue` since that would have a global value.

@holroy holroy mentioned this issue Jan 23, 2025
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

2 participants