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

Allow for subclassed types #158

Open
mkrizek opened this issue Feb 19, 2018 · 5 comments
Open

Allow for subclassed types #158

mkrizek opened this issue Feb 19, 2018 · 5 comments

Comments

@mkrizek
Copy link

mkrizek commented Feb 19, 2018

A little background first, in Ansible there is a json_query filter plugin which uses jmespath to query json. There is an issue open where users of that plugin get the following error:

JMESPathTypeError: In function contains(), invalid type for value: irb.1111, expected one of: ['array', 'string'], received: "unknown"

The comment that summarizes the issue is here ansible/ansible#27299 (comment).

The error is caused by the fact that Ansible uses its own types for strings. One of the hacks we've come up with was:

jmespath.functions.REVERSE_TYPES_MAP['string'] = jmespath.functions.REVERSE_TYPES_MAP['string'] + ('AnsibleUnicode', 'AnsibleUnsafeText',)

which seems weird since I am pretty sure REVERSE_TYPES_MAP is not supposed to be public.

is there a proper way to do this? If not, is this something that would be considered to be added?

Thanks!

@mkrizek
Copy link
Author

mkrizek commented Feb 28, 2018

cc @jamesls

@jamesls
Copy link
Member

jamesls commented Feb 28, 2018

There's not a good way to do this now throuhg a public interface but I'm not opposed to adding something to make this easier. Having less restrictive type checking has come up a few times.

@jeking3
Copy link

jeking3 commented Nov 6, 2018

@jamesls would you be able to add this public interface that allows the consumer of jmespath to teach jmespath about additional types that are convertible to string? Or do you need someone in the community to do it?

@jeking3
Copy link

jeking3 commented Dec 6, 2018

@jamesls are you still there?

@jamesls
Copy link
Member

jamesls commented Mar 4, 2020

So I'm not opposed to this feature, but offhand I don't have any thoughts on a better public API for this. If anyone has suggestions, I'm open to it. I suppose we'd add something to the Options class?

Once we have an interface we like, I can take a crack at implementing this.

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

No branches or pull requests

3 participants