Skip to content

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

@MinalRajendra

Description

@MinalRajendra

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'>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions