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

pattern rule not working with all scalar types #177

Open
rpieterick opened this issue Oct 26, 2020 · 1 comment
Open

pattern rule not working with all scalar types #177

rpieterick opened this issue Oct 26, 2020 · 1 comment

Comments

@rpieterick
Copy link

Environment

  • Python version: 3.6.9
  • PyKwalify version: 1.7.0

Documentation states the pattern rule works for all scalar types.
It appears that with the commit for issue #47, the pattern rule only works for string values.

Steps to Reproduce

  1. pykwalify -s schema.yaml -d data.yaml

Schema

type: map
mapping:
  "=":
    type: scalar
    pattern: .*

Data

boolean: true
number: 1
string1: truE
string2: 127.0.0.1

Expected Behavior

Validation passes.

Observed Behavior

 ERROR - validation.invalid
 ERROR -  --- All found errors ---
 ERROR - [u"Value 'True' does not match pattern '.*'. Path: '/boolean'", u"Value '1' does not match pattern '.*'. Path: '/number'"]
Traceback (most recent call last):
  File "/usr/local/bin/pykwalify", line 11, in <module>
    sys.exit(cli_entrypoint())
  File "/usr/local/lib/python2.7/dist-packages/pykwalify/cli.py", line 95, in cli_entrypoint
    run(parse_cli())
  File "/usr/local/lib/python2.7/dist-packages/pykwalify/cli.py", line 82, in run
    c.validate()
  File "/usr/local/lib/python2.7/dist-packages/pykwalify/core.py", line 167, in validate
    error_msg=u'.\n - '.join(self.validation_errors)))
pykwalify.errors.SchemaError: <SchemaError: error code 2: Schema validation failed:
 - Value 'True' does not match pattern '.*'. Path: '/boolean'.
 - Value '1' does not match pattern '.*'. Path: '/number'.: Path: '/'>
@Grokzen
Copy link
Owner

Grokzen commented Dec 30, 2020

@rpieterick So there is two solutions to this. Either we fully ignore pattern rule on types that is not really a string compatible scalar types and you as a user have to explicitly sort out the data you send in and only string compatible values will be checked and the others will be ignored. Or we always attempt to do a str() convert of the value and check the pattern against that and let the user provide something that is str() compatible. I think i will lean towards the second option where it will be attempted first and then possibly fail.

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

2 participants