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

Infringed constraint on array values causes a type-error #759

Closed
pierredittgen opened this issue Mar 17, 2021 · 3 comments · Fixed by #767
Closed

Infringed constraint on array values causes a type-error #759

pierredittgen opened this issue Mar 17, 2021 · 3 comments · Fixed by #767
Labels
bug Something isn't working

Comments

@pierredittgen
Copy link
Contributor

Overview

I'm really excited to use the new feature to constraint array item values (see #627) but I face a problem with errors raised in the validation report.

Given array_sample.csv file:

field1
"[""a""]"
"[""a"",""b""]"
"[""a"",""b"",""c""]"
"[""c""]"

I wrote a first simple schema (array_schema.json file) to insure that field1 contains array values:

{
  "$schema": "https://specs.frictionlessdata.io/schemas/table-schema.json",
  "fields": [
    {
      "name": "field1",
      "type": "array"
    }
  ]
}

I can check that my CSV file is ok:

> frictionless validate --schema array_schema.json array_sample.csv
# -----
# valid: array_sample.csv
# -----

Now, I want to go further and check that array items are only "a" or "b". I extend my schema using arrayItem property (array_with_contraints_schema.json file):

{
  "$schema": "https://specs.frictionlessdata.io/schemas/table-schema.json",
  "fields": [
    {
      "name": "field1",
      "type": "array",
      "arrayItem": { "constraints": { "enum": ["a", "b"] } }
    }
  ]
}

Re-run validate:
```bash
> frictionless validate --schema array_with_contraints_schema.json array_sample.csv 
# -------
# invalid: array_sample.csv
# -------

===  =====  ==========  =============================================================================================================
row  field  code        message                                                                                                      
===  =====  ==========  =============================================================================================================
  4      1  type-error  Type error in the cell "["a","b","c"]" in row "4" and field "field1" at position "1": type is "array/default"
  5      1  type-error  Type error in the cell "["c"]" in row "5" and field "field1" at position "1": type is "array/default"        
===  =====  ==========  =============================================================================================================

I don't understand why I get type-error errors. IMO these errors are not relative to type infrigement. Validate only on type (with array_schema.json) reveals no errors.

Would it be possible to get constraint-error errors instead with a clearer message?

Thx


Please preserve this line to notify @roll (lead of this repository)

@roll roll added the bug Something isn't working label Mar 18, 2021
@roll
Copy link
Member

roll commented Mar 21, 2021

Thanks! I'll handle it

@roll
Copy link
Member

roll commented Mar 23, 2021

Could you please test it with frictionless@4.2

@pierredittgen
Copy link
Contributor Author

frictionless validate --schema array_with_contraints_schema.json array_sample.csv
# -------
# invalid: array_sample.csv
# -------

===  =====  ================  =================================================================================================================================================================
row  field  code              message                                                                                                                                                          
===  =====  ================  =================================================================================================================================================================
  4      1  constraint-error  The cell "["a","b","c"]" in row at position "4" and field "field1" at position "1" does not conform to a constraint: array item constraint "enum" is "['a', 'b']"
  5      1  constraint-error  The cell "["c"]" in row at position "5" and field "field1" at position "1" does not conform to a constraint: array item constraint "enum" is "['a', 'b']"        
===  =====  ================  =================================================================================================================================================================

Much, much better!

Thanks @roll!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants