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

Getting AttributeError: 'str' object has no attribute 'get' #123

Closed
pratikjoy7 opened this issue Mar 3, 2018 · 1 comment
Closed

Getting AttributeError: 'str' object has no attribute 'get' #123

pratikjoy7 opened this issue Mar 3, 2018 · 1 comment

Comments

@pratikjoy7
Copy link

pratikjoy7 commented Mar 3, 2018

The structure of my yaml data is like this -

item_A:
  key_one: some_str_value
  key_two:
    - some_str_value_one
    - some_str_value_two
item_B:
  key_one: some_str_value
  key_two:
    - some_other_str_value_one
    - some_other_str_value_two

The schema I wrote is this -

type: map
mapping: 
  item:
    type: map
    required: yes
    mapping:
      key_one: 
        type: str
        required: yes
      key_two: seq
      required: yes
      seq:
        - type: str

Where am I making the mistake here? Thanks in advance.

@Grokzen
Copy link
Owner

Grokzen commented Mar 6, 2018

@pratikjoy7 First you have wrong schema defenitions that is not valid. I think i cleaned it up for you to the following schema

type: map
mapping: 
  item:
    type: map
    required: True
    mapping:
      key_one:
        type: str
        required: True
      key_two:
        seq:
          - type: str

That passed for me on my dev env at least.

The second problem is that your schema will never be able to validate your data as it stands right now. In your first level of mapping you define item in your schema. This name must be a exact match to the key in your data. But your keys are item_A and item_B and validation is strict and not from left to right matching. Below that it should all be proper and work as expected. If you need the "left to right" type of matching then you should look into "regex" feature in the docs because that will help you on that front.

Please read up on the docs for more details on the schema support. Also please review the example files for references on how to implement schema files.

@Grokzen Grokzen closed this as completed Mar 6, 2018
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