Comments (14)
Thanks. And thanks once again for pointing it out.
I'm working on preventing the above bug from occurring by preventing the combination of Maps / Seqs using the Or validator. I'll put a message hinting that the end user should use revalidation for their purposes so future users won't fall down the same rabbit hole.
from strictyaml.
Yeah, this is an unfortunate bug. Thank you for bringing it to my attention.
It's a natural side effect of the stateful way in which mappings are parsed via the validator (I did it statelessly for a while but that made validations take an unconscionably long time to parse).
This can, of course, be avoided by using Optional, which is the recommended way of parsing the way you just did:
schema = Map(
{
"configuration": MapPattern(
Str(),
Map({
"helptext": Str(),
Optional("min"): Int(),
}),
minimum_keys=1
),
}
)
I'm considering a 'fix' being to prevent Or validation combinations which include more than one Map. I had originally intended Or validation to solely be used like so:
"EmptyNone() | Str() | Map({...})"
Rather than as a way of combining Maps:
"Map({...}) | Map({....}).
from strictyaml.
Hey, thank you for the response.
My original usecase and how i found the bug is a little more complex than the example i used above. I don't think i can achieve this with Optional
:
I want to define and validate a list of components in YAML. A component can be of a certain type (A or B) and each component type can have its own attributes, depending on the type. For example we have for component A:
Map({
"type": Str(), # type A
"helptext": Str(),
}),
And component B looks like this:
Map({
"type": Str(), # type B
"min": Int(),
"max": Int(),
}),
And i would like to create list that consists, for example, of three times component A and two times component B and then again tree times component A. The order is not fix, but it is important. (just as a random example, the numbers can change)
Shorter example:
configuration
component_a:
type: A
helptext: "some text"
component_b:
type: B
min: 1
max: 10
component_a:
type: A
helptext: "some other text"
It relativly easy to write the YAML for that but i have a super hard time to find a way to create a schema for that, given that the validator is stateful.
Do you think it is possible to validate the YAML with the limitations?
from strictyaml.
from strictyaml.
from strictyaml.
Looks like I won't be able to get it done this weekend, but I'm still working on it.
from strictyaml.
No worries. Anything i can help you with?
from strictyaml.
from strictyaml.
I think i understand what you are getting at but i have zero idea how to do that, yet :)
Essentially, this would move away from a "static" large schema definition to a more dynamic validation, correct?
from strictyaml.
from strictyaml.
from strictyaml.
ha, this actually works well!
I think we should leave the ticket open for the original bug but my problem is solved for now. I can work with that. Thank you very much!
from strictyaml.
OrValidation is now disallowed using multiple MapValidators in version 1.0.1.
from strictyaml.
I have a small question,
Though it's not stated that project version is following semantic versioning,
my general feeling says that patch version update shouldn't introduce breaking changes.
Do you have some policy about versioning for this project?
from strictyaml.
Related Issues (20)
- Problem loading document with a single string
- Repeated revalidate() raises Invalid state HOT 2
- Failed revalidation leads to inconsistant state
- Fasjo HOT 3
- Website fails to acknowledge that the Norway problem was fixed in YAML 1.2 HOT 2
- strictyaml does not act as "a near-drop in replacement for pyyaml" HOT 4
- The type order of optional arguments affects the results HOT 2
- Date vs Datetime HOT 2
- Support python2.7.18 HOT 2
- 1.7.0 is broken (cannot import name 'ruamel' from partially initialized module 'strictyaml') HOT 5
- Map containing only Optionals does not validate an empty dict HOT 1
- as_document and load have dissimilar results for CommaSeparated(Int())
- Doesn't Work At All For Lists / Arrays? HOT 4
- New lines after comment line causes `NotImplementedError`
- Feature request/Question: "Optionalize" maps HOT 1
- Thoughts regarding case-sensitivity of keys HOT 6
- Why not: non-Turing complete configuration languages
- Cannot iterate on emtpy list
- BUG: MapCombined documentation different traceback
- Feature: strictyaml.scalar.Time
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strictyaml.