Dependencies used to work above the subdocument
See original GitHub issueI posted this as a question Stack Overflow at http://stackoverflow.com/questions/40749079/how-can-a-cerberus-dependency-reference-a-field-higher-up-in-the-document but some experimenting shows a difference in behavior between 0.9.2 and 1.0.1, so depending on the intended behavior, this is either a bug report or a feature request.
I am trying to create a schema for documents that have dependencies that reference fields higher up in the document. For example:
document = {
'packages': {
'some-package': {'version': 1}
},
'build-steps': {
'needs-some-package': {'foo': 'bar'},
'other-thing': {'funky': 'stuff'}
}
}
schema = {
'packages': {
'type': 'dict',
'valueschema': {
'type': 'dict'
}
},
'build-steps': {
'type': 'dict',
'schema': {
'needs-some-package': {
'type': 'dict',
'dependencies': 'packages.some-package'
},
'other-thing': {
'type': 'dict'
}
}
}
}
On 0.9.2, this validates, but on 1.0.1 it does not. The stable docs at http://docs.python-cerberus.org/en/stable/validation-rules.html#dependencies say that the dot notation (“packages.some-package”) is for sub-document dependencies and that it was added in 0.8.1. The dot notation example in the docs, though, demonstrates that dependencies can be on adjacent subdocuments, too. But since the examples all use top-level fields, it’s not apparent whether it’s supposed to be possible to reference dependencies that are not adjacent or within the subdocument.
Does that mean that 1.0.1 is actually the intended behavior and 0.9.2’s working was a bug? Or is the bug in 1.0.1?
If it is behaving as intended, then this is a feature request to provide some means of addressing dependencies outside the scope. Perhaps it could be like a filesystem, where there is notation for both an absolute reference from the root of the document or relative reference that can go up through parents with something like “…/…/the-field”. Obviously would have to be a different notation than a filesystem’s dot and slash way, because of the existing dot notation.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
I spent half a day today trying to figure out how this works and why it doesn’t work even though the documentation says it should. And then figuring out it works in 0.9.2 and if I want it to work I’ll miss a lot of functionality from the new version.
It’d be a very nice thing to have.
Yes.