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

EmptyDrop and Object indexing #477

Open
rydrman opened this issue Oct 5, 2022 · 7 comments · May be fixed by #496
Open

EmptyDrop and Object indexing #477

rydrman opened this issue Oct 5, 2022 · 7 comments · May be fixed by #496

Comments

@rydrman
Copy link

rydrman commented Oct 5, 2022

liquid-rust version: 0.26.0
rust version: 1.63.0
OS: linux

I've been referencing this page of the liquid docs, and my understanding of the nil and EmptyDrop type is that both of the following should be possible:

{% assign var = value | default: 42 %}
{% assign var = data.value | default: 42 %}

In using liquid-rust, however, I'm finding that the second case fails for me if data.value does not already exist. I get an error like:

liquid: Unknown index
  with:
    variable=data
    requested index=value
    available indexes=other, more_data
from: {% assign var = data["value"] | default : 42%}

I was looking for an existing issue for this but didn't find anything, am I missing something?

@epage
Copy link
Member

epage commented Oct 7, 2022

Its been a while since I've dug into the meaning of this on both sides but I think we were aiming for strict_variables and strict_filters exclusively

From https://github.com/Shopify/liquid

By default, the renderer doesn't raise or in any other way notify you if some variables or filters are missing, i.e. not passed to the render method. You can improve this situation by passing strict_variables: true and/or strict_filters: true options to the render method. When one of these options is set to true, all errors about undefined variables and undefined filters will be stored in errors array of a Liquid::Template instance. Here are some examples:

@rydrman
Copy link
Author

rydrman commented Oct 7, 2022

I think that's a fair goal for values leaving a filter chain, but it seems like the inconsistent behaviour between the two cases above is surprising. I'm trying to figure out if there's even a way to handle this case in the template, because as far as I can tell there's no way to check if some value is set without getting this error

@epage
Copy link
Member

epage commented Oct 7, 2022

it seems like the inconsistent behaviour between the two cases above is surprisin

Yes, I had missed the inconsistency in my first read through. Thats something that needs looking into.

I'm trying to figure out if there's even a way to handle this case in the template, because as far as I can tell there's no way to check if some value is set without getting this error

You can do {% if value %} (test) or `{% data contains "value" %} (test).

@rydrman
Copy link
Author

rydrman commented Oct 12, 2022

Thanks, if you have any inclinations on where I can poke at this issue in the codebase I'd be happy to see if I can resolve the inconsistency

@rydrman
Copy link
Author

rydrman commented Apr 6, 2023

Any thoughts or follow-up on this one?

@rydrman rydrman linked a pull request Apr 8, 2023 that will close this issue
1 task
@epage
Copy link
Member

epage commented Sep 25, 2023

The question for any of this is what does Ruby's implementation do with those strict flags set. Any discussion or PR should be focused on that.

@rydrman
Copy link
Author

rydrman commented Sep 25, 2023

Okay, I've done a repl test against the latest ruby gem and found that filters are not allowed to start with undefined variables when strict_variables is set - which means the former case is incorrect for this implementation, ie {% assign var = value | default: 42 %} does not currently error, but should

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants