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

any() inside included element causes error #28

Closed
ghost opened this issue Sep 22, 2016 · 5 comments
Closed

any() inside included element causes error #28

ghost opened this issue Sep 22, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 22, 2016

The following schema results in an error while parsing the schema:

test_1: include('test_2')

---
test_2: any(str(), int())

Relevant part of stack trace:

File "/usr/local/lib/python2.7/site-packages/yamale/yamale.py", line 17, in make_schema
s.add_include(raw_schema)
File "/usr/local/lib/python2.7/site-packages/yamale/schema/schema.py", line 20, in add_include
validators=self.validators)
File "/usr/local/lib/python2.7/site-packages/yamale/schema/schema.py", line 14, in init
self._schema = self._process_schema(schema_dict, self.validators)
File "/usr/local/lib/python2.7/site-packages/yamale/schema/schema.py", line 36, in _process_schema
raise SyntaxError(str(e) + ' at node '%s' in file %s' % (key, self.name))
SyntaxError: Invalid schema expression: 'i'. name 'i' is not defined at node '11' in file test_2

This is with Python 2.7 if that matters

So, if I want an element to contain one of two possible types of value, I need to do something like this instead and do some additional validation in the code that at least one of them is present:

test_1: include('test_2')

---
test_2:
  test_3: str(required=False)
  test_4: int(required=False)

Not sure if this is intended. Am I missing something or is there no neater way to do this?
Thanks!

@ghost ghost changed the title any() inside included field causes error any() inside included element causes error Sep 22, 2016
@cblakkan
Copy link
Member

The original schema you posted is this:

test_1: include('test_2')
---
test_2: any(str(), int())

I think what you want is:

test_1: any(str(), int())

The include expects a dictionary.

@ghost
Copy link
Author

ghost commented Sep 22, 2016

Hi! Thanks for the quick response and for supporting this great project!

I think in my attempt to isolate the issue in the example I over-simplified it. Your suggestion does not quite work for me, as I need to have my any() inside a map():

test_1: include('test_2')
---
test_2:
  foo: >
    map(
      any(
        include('test_3),
        include('test_4')
      )
    )
test_3:
  foo: str()
test_4:
  bar: int()

The above causes an error, and I don't see a good way to re-format it if I can't pull the any() out into an include...

@ghost
Copy link
Author

ghost commented Sep 22, 2016

Just realized there is a typo in the above example and it works if I fix it... I might be confusing myself. Let me try a few things. The schema I'm working with is fairly complicated and it's hard to isolate the issues :P

@ghost
Copy link
Author

ghost commented Sep 22, 2016

Okay yes I ran into a syntax error and misinterpreted it when I was trying an alternative way to write the schema. Once I fixed the syntax error it worked. Sorry to bother!

@ghost ghost closed this as completed Sep 22, 2016
@cblakkan
Copy link
Member

No problem, glad to help.

This issue was closed.
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

1 participant