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

ArgType for String should probably not call ToString on all types #596

Open
mitsuhiko opened this issue Oct 13, 2024 · 2 comments
Open

ArgType for String should probably not call ToString on all types #596

mitsuhiko opened this issue Oct 13, 2024 · 2 comments

Comments

@mitsuhiko
Copy link
Owner

There are some types which probably are fine to stringify implicity:

  • bool
  • number
  • string

But there are some where you can get really confusing behavior. The most notable one is Kwargs. This for instance can cause some unknown keyword arguments to be accepted and converted (see #594).

{{ ('hello', 'world') | join(d=' ') }}
  --> hello{"d": " "}world
@mitsuhiko mitsuhiko added this to the MiniJinja 3.0 milestone Oct 13, 2024
@mitsuhiko
Copy link
Owner Author

On further thought we actually only want to disallow Kwargs here somehow. The join filter actually does stringify anything on Jinja2.

@mitsuhiko
Copy link
Owner Author

I think the real issue is that we're using a Value to funnel keyword arguments and that is just always naughty. At the very least the ArgType implementation for the string types should refuse to stringify a kwargs object but I feel like most filters and functions would not want to magically have a Kwargs value show up in Value either.

So one option would be to say that ArgType for Value actually refuses to accept a Kwargs object and a separate ValueOrKwargs type would be needed to hold it. That would break some stuff but probably make it way more explicit about what is happening.

The part of Kwargs not stringifying I think should be fixed as a bugfix because that for sure was unintentional.

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

No branches or pull requests

1 participant