Giter VIP home page Giter VIP logo

Comments (7)

jmtd avatar jmtd commented on June 23, 2024

I think I've hit this. For completion's sake here's a minimal test case, and the exception thrown

data:

 - zomg: lol

schema:

seq:
  - map:
      allowempty: True

exception:

Traceback (most recent call last):
  File "kwalbug.py", line 20, in <module>
    c.validate(raise_exception=True)
  File "pykwalify/core.py", line 147, in validate
    self._start_validate(self.source)
  File "pykwalify/core.py", line 187, in _start_validate
    root_rule = Rule(schema=self.schema)
  File "pykwalify/rule.py", line 62, in __init__
    self.init(schema, "")
  File "pykwalify/rule.py", line 346, in init
    func_mapping[k](v, rule, path)
  File "pykwalify/rule.py", line 833, in init_mapping_value
    rule.init(v, u"{}/mapping/{}".format(path, k))
  File "pykwalify/rule.py", line 346, in init
    func_mapping[k](v, rule, path)
  File "pykwalify/rule.py", line 764, in init_sequence_value
    rule.init(elem, u"{}/sequence/{}".format(path, i))
  File "pykwalify/rule.py", line 346, in init
    func_mapping[k](v, rule, path)
  File "pykwalify/rule.py", line 833, in init_mapping_value
    rule.init(v, u"{}/mapping/{}".format(path, k))
  File "pykwalify/rule.py", line 278, in init
    include = schema.get("include", None)
AttributeError: 'bool' object has no attribute 'get'

Version: 1.5.1 (via PyPI)

from pykwalify.

jmtd avatar jmtd commented on June 23, 2024

..actually I hit it with even the following, no seq involved

schema:

map:
  foo: {type: str}
  allowempty: True

data:

foo: asads
bar: asad

from pykwalify.

Grokzen avatar Grokzen commented on June 23, 2024

@jmtd Have you tried the schema/data with the latest commit in unstable branch?

from pykwalify.

jmtd avatar jmtd commented on June 23, 2024

Hi, sorry for the delay. Yes I can confirm this with 6596293

from pykwalify.

Grokzen avatar Grokzen commented on June 23, 2024

@smalleni Your specific usecase and schema you posted is now fixed as of this commit cd012c9 and you can see your data/schema was used and it now validated properly as expected.

@smalleni @jmtd I would NOT recommend to use the map: keyword for now becuase it is still buggy with the first example you provided @jmtd

# DO NOT USE
seq:
  - map:
      allowempty: True

# USE THIS INSTEAD
type: seq
sequence:
  - type: map
    allowempty: True

I will keep investigating why seq & map bugs out in that way.

from pykwalify.

Grokzen avatar Grokzen commented on June 23, 2024

@jmtd A comment after some thinking regarding the problems with seq: and - map: is that it is currently not possible to have allowempty: True in the way i showed in the last comment becuase the reason that keyword/shortcut was implemented was to make it easier to write instead of having to specify type: map & mapping: {...} so it would be easier to write and understand what you wanted. The problem with this is that all subkeys that you specify inside the value part for the map will be considered a regular key/value pair that it should validate against data and not a keyword that it acctually is. I consider this correct behavriour from the implementation and i basically say that all extra keywords that you normally can specify for a seq and map keywords is not possible to have in the schema as it is right now. The only consitent way would be to do the following:

seq:
  - map:
      allowempty: True
      mapping: {}

but by doing this it makes it really confusing compared to the normal way it is done and i would have to rewrite alot of logic just to change it into this and that is not something i will do. So the current implementaitno and the suggestion/directive i mentioned above to use USE THIS INSTEAD section stands as the only supported way to use extra keywords for a map type.

I am closing this issue becuase there is no more issues to deal within this issue. The original issue was solved as mentioned above through commit cd012c9

from pykwalify.

jmtd avatar jmtd commented on June 23, 2024

I think I understand, thank you.

from pykwalify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.