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

issue while using "unique: true" for the sequence data type #196

Open
MinalRajendra opened this issue Nov 7, 2022 · 3 comments
Open

issue while using "unique: true" for the sequence data type #196

MinalRajendra opened this issue Nov 7, 2022 · 3 comments

Comments

@MinalRajendra
Copy link

MinalRajendra commented Nov 7, 2022

Environment

  • Python version: 3.5.2
  • PyKwalify version: 1.8.0

Steps to Reproduce

  1. create input YML file as below
    test.yml

mydata:
name: 123
age: ABCD
hobbies: [cooking, painting, cooking]

  1. create YML schema as below

type: map
mapping:
 mydata:
  type: map
  mapping:
    name:
      type: str
      range:
       min: 1
       max: 10
    age:
       type: int
       range:
          min: 21
          max: 100
    hobbies:
       type: seq
       sequence:
       -  type: str
          unique: true
          required: true
  1. Write Python test case for validation as below
    validate_yml.py
#! /usr/bin/python3

@author: Minal Deshmukh

import pykwalify
from pykwalify.core import Core, SchemaError
from pykwalify.errors import RuleError

yaml_file = "./test.yml"
schema_file = "./schema.yml"
yaml_schema = Core(source_file=yaml_file, schema_files=[schema_file])
try:
    pykwalify.init_logging(0)
    yaml_schema.validate(raise_exception=True)
except (SchemaError, RuleError):
    for error in yaml_schema.errors:
        print("error -->",error)
        print ("Data Type of error is -->",type(error))
  1. Execute test case as below
    python3 validate_yml.py

OUTPUT

error --> Value 'ABCD' is not of type 'int'. Path: '/mydata/age'
Data Type of error is --> <class 'pykwalify.errors.SchemaError.SchemaErrorEntry'>
error --> Value '123' is not of type 'str'. Path: '/mydata/name'
Data Type of error is --> <class 'pykwalify.errors.SchemaError.SchemaErrorEntry'>
error --> Value 'cooking' is not unique. Previous path: '/mydata/hobbies/0'. Path: '/mydata/hobbies/2'
Data Type of error is --> <class 'str'>

Schema

type: map
mapping:
 mydata:
  type: map
  mapping:
    name:
      type: str
      range:
       min: 1
       max: 10
    age:
       type: int
       range:
          min: 21
          max: 100
    hobbies:
       type: seq
       sequence:
       -  type: str
          unique: true
          required: true

Data

mydata:
    name: 123
    age: ABCD
    hobbies: [cooking, painting, cooking]

Expected Behavior

Expected data type of the error below is 'pykwalify.errors.SchemaError.SchemaErrorEntry'

error --> Value 'cooking' is not unique. Previous path: '/mydata/hobbies/0'. Path: '/mydata/hobbies/2'
Data Type of error is --> <class 'str'>

Observed Behavior

Data type is different than the other error data types
error --> Value 'cooking' is not unique. Previous path: '/mydata/hobbies/0'. Path: '/mydata/hobbies/2'
Data Type of error is --> <class 'str'>

@Grokzen
Copy link
Owner

Grokzen commented Nov 8, 2022

Mkay, good catch. I think the error stems from 2 different places

https://github.com/Grokzen/pykwalify/blob/master/pykwalify/core.py#L449 is where the errors is stored during parsing to later be added to the errors list. But when the iterator runs over this temporary lits here https://github.com/Grokzen/pykwalify/blob/master/pykwalify/core.py#L468 we run iteration over a dict and i guess you get out the keys only and in this case that would be the __repr__ part of the key and not the exception object itself.

@MinalRajendra
Copy link
Author

Mkay, good catch. I think the error stems from 2 different places

https://github.com/Grokzen/pykwalify/blob/master/pykwalify/core.py#L449 is where the errors is stored during parsing to later be added to the errors list. But when the iterator runs over this temporary lits here https://github.com/Grokzen/pykwalify/blob/master/pykwalify/core.py#L468 we run iteration over a dict and i guess you get out the keys only and in this case that would be the __repr__ part of the key and not the exception object itself.

Thank you for looking into it & your immediate response.
When can we expect fix for this issue?

@Grokzen
Copy link
Owner

Grokzen commented Nov 9, 2022

@MinalRajendra I can't give any estimate as i can't give this project to much of my free time right now. If you want a fix, the absolute fastest way is for you to test to modify the parts above i mentioned and submit a PR. Otherwise, maybe in Dec, most likley in Jan at this point

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