question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom boolean values create a field_error when trying to validate

See original GitHub issue

Overview

We have a data package that defines custom values to represent “true” or “false” on boolean fields, as defined in the specs. When trying to validate this, frictionless-py raises a field_error.

How to reproduce

  1. Create a file named bool.csv like this:
id,question
0,confirm
1,deny
2,deny
3,confirm
  1. Create a Python environment and pip install frictionless==4.1.2.

  2. Code to test:

from frictionless import describe_resource, validate_schema, validate_resource

r = describe_resource('bool.csv')
f = r.schema.get_field('question')
f.type = 'boolean'
f.format = {
        'trueValues' : ['confirm'],
        'falseValues' : ['deny']
}
  1. Now the problem:
[6]: validate_schema(r.schema)

[6]: {'version': '4.2.1',
 'time': 0.001,
 'errors': [{'code': 'field-error',
   'name': 'Field Error',
   'tags': [],
   'note': '"{\'name\': \'question\', \'type\': \'boolean\', \'format\': {\'trueValues\': [\'confirm\'], \'falseValues\': [\'deny\']}} is not valid under any of the given schemas" at "" in metadata and at "anyOf" in profile',
   'message': 'Field is not valid: "{\'name\': \'question\', \'type\': \'boolean\', \'format\': {\'trueValues\': [\'confirm\'], \'falseValues\': [\'deny\']}} is not valid under any of the given schemas" at "" in metadata and at "anyOf" in profile',
   'description': 'Provided field is not valid.'}],
 'tasks': [],
 'stats': {'errors': 1, 'tasks': 0},
 'valid': False}
  1. Also:
[7]: validate_resource(r)

[7]: {'version': '4.2.1',
 'time': 0.004,
 'errors': [{'code': 'field-error',
   'name': 'Field Error',
   'tags': [],
   'note': '"{\'name\': \'question\', \'type\': \'boolean\', \'format\': {\'trueValues\': [\'confirm\'], \'falseValues\': [\'deny\']}} is not valid under any of the given schemas" at "" in metadata and at "anyOf" in profile',
   'message': 'Field is not valid: "{\'name\': \'question\', \'type\': \'boolean\', \'format\': {\'trueValues\': [\'confirm\'], \'falseValues\': [\'deny\']}} is not valid under any of the given schemas" at "" in metadata and at "anyOf" in profile',
   'description': 'Provided field is not valid.'}],
 'tasks': [],
 'stats': {'errors': 1, 'tasks': 0},
 'valid': False}

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
augusto-herrmanncommented, Mar 26, 2021

Oh, I see.

Thanks for looking into it, @roll . 😄

Sorry for misunderstanding the specs. 😟

0reactions
rollcommented, Mar 26, 2021

Hi @augusto-herrmann

I guess, the specs’ text is confusing. It’s not the field.format it’s the field.[property]:

from pprint import pprint
from frictionless import describe_resource, validate_schema, validate_resource

r = describe_resource("tmp/issue773.csv")
f = r.schema.get_field("question")
f.type = "boolean"
f.true_values = ["confirm"]
f.false_values = ["deny"]
pprint(r.schema.metadata_valid)
pprint(r.schema)
True
{'fields': [{'name': 'id', 'type': 'integer'},
            {'falseValues': ['deny'],
             'name': 'question',
             'trueValues': ['confirm'],
             'type': 'boolean'}]}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set FieldError field in a custom jsr 303 validation
I am creating a webservice in spring. I have a Params DTO which is nested in my OtherParentDTO's. Each request may contain only...
Read more >
FieldError (Spring Framework 6.0.3 API)
Encapsulates a field error, that is, a reason for rejecting a specific field value. See the DefaultMessageCodesResolver javadoc for details on how a...
Read more >
Spring Validation Example - Spring MVC Form Validator
We can create our custom validator implementations in two ways - the first one is to create an annotation that confirms to the...
Read more >
Example usage for org.springframework ... - Java2s.com
Create a new FieldError instance. Usage. From source file:com.company.simple.util.validator.GlobeValidator.java protected void processConstraintViolations( ...
Read more >
zod/ERROR_HANDLING.md at master · colinhacks/zod - GitHub
This guide explains Zod's internal error handling system, and the various ways you can customize it for your purposes. ZodError. All validation errors...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found