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

Empty aliases: in front matter results value: "null" string

Open zsviczian opened this issue 2 years ago • 9 comments

What happened?

See this conversation for details: https://github.com/zsviczian/excalibrain/issues/83

image

In summary leaving aliases: in the frontmatter empty result in page.alisases.values = ["null"] instead of values=[].

instead of this

{
  "aliases": {
    "values": [
      "null"
    ],
}

I think it should be rather this:

{
  "aliases": {
    "values": [],
}

@SunnyOd can you provide the dataview and obsidian version and operating system you are using?

DQL

No response

JS

No response

Dataview Version

N/A

Obsidian Version

N/A

OS

Windows

zsviczian avatar Aug 17 '22 18:08 zsviczian

Haha this is a good one. Does this happen in the metadataCache as well?

AB1908 avatar Aug 17 '22 18:08 AB1908

@SunnyOd can you provide the dataview and obsidian version and operating system you are using?

DQL

Sure... I'm on:

  • Fedora Linux (i3 Spin): 5.18.16-200.fc36.x86_64
  • Obsidian: 0.15.9
  • Dataview: 0.5.41

SunnyOd avatar Aug 17 '22 18:08 SunnyOd

You probably want file.aliases, not aliases - the top level metadata in dataview pages are just literal copies of whatever your frontmatter + inline fields are.

blacksmithgu avatar Aug 18 '22 02:08 blacksmithgu

@blacksmithgu, I'm using file.aliases. In this case top level aliases is better, though still not good. It holds an item of value [null] not ['null'], but at the moment I am checking if aliases.length > 0 which in both cases will result in a false positive. I could change the logic, however I think instead of [null] and ['null'] it would be more proper to have [].

image

Here's my code for reading aliases: https://github.com/zsviczian/excalibrain/blob/e5031ede20dd04737e4568471ea3b0d35b0786c8/src/graph/Page.ts#L152-L158

@AB1908, it seems the value is [null] in metadatacache image

zsviczian avatar Aug 18 '22 06:08 zsviczian

I raised a question with Licat on OMG on the topic of [null] vs. []. I can argue for both, but on balance I still feel that [] would be cleaner. https://discord.com/channels/686053708261228577/840286264964022302/1009707558388367460

zsviczian avatar Aug 18 '22 06:08 zsviczian

Ah, I see. The difference here is

aliases:
-

Versus

aliases:

The first one pretty clearly looks like [null] to me, at least going by the YAML spec. I could also maybe see [""], but I don't think [] is a valid parse unless you make a special case for the treatment of aliases.

blacksmithgu avatar Aug 18 '22 07:08 blacksmithgu

Thanks! [""] is definitely better than ["null"]. I will add additional validations to my logic to check if value is null or "".

zsviczian avatar Aug 18 '22 09:08 zsviczian

Feedback from Licat referring to [null]:

That's literally how yaml parses empty fields. Internally we have a function to type check and recognize things like aliases.

Thus the thing to consider is if you want to change DataView at the file level from ["null"] to either [null] or [""].

zsviczian avatar Aug 18 '22 14:08 zsviczian

Upon reflection, in don't think it's a breaking change to just have dataview eliminate empty strings and nulls and return [].

blacksmithgu avatar Aug 18 '22 17:08 blacksmithgu