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

"const" can produce broken code #29

Closed
jofo-ivbar opened this issue Sep 26, 2018 · 1 comment
Closed

"const" can produce broken code #29

jofo-ivbar opened this issue Sep 26, 2018 · 1 comment

Comments

@jofo-ivbar
Copy link

I can't get the "const" keyword to work properly for string values:

In [12]: fastjsonschema.compile({"const": "a"})("a")
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-12-ab19503ee02c> in <module>()
----> 1 fastjsonschema.compile({"const": "a"})("a")

<string> in validate(data)

NameError: name 'a' is not defined

Looking the code produced by the compile_to_code function, it seems that the value "a" is just not properly quoted:

VERSION = "2.3"
from fastjsonschema import JsonSchemaException


NoneType = type(None)

def validate(data):
    if data != a:
        raise JsonSchemaException("data must be same as const definition")
    return data

Indeed, it works for values that don't require quoting, like integers.

horejsek added a commit that referenced this issue Sep 27, 2018
@horejsek
Copy link
Owner

Good catch! Fixed in master and I will publish in v2.4 it sometime today.

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