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.

Dependencies used to work above the subdocument

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
matejpipiskacommented, Dec 1, 2016

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.

0reactions
nicolaiaroccicommented, Dec 7, 2016

Yes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose find/update subdocument - Stack Overflow
If you have an array of subdocuments, you can fetch the desired one with the id() method provided by Mongoose. Then you can...
Read more >
Validation Rules — Cerberus is a lightweight and extensible ...
1: Support for sub-document fields as dependencies. Changed in version 0.8: Support for dependencies as a dictionary. New in version 0.7.
Read more >
Asynchronously Perform Subdocument Mutations in ...
Learn how to perform Couchbase Server subdocument mutations in parallel using the Go programming language and Goroutines.
Read more >
A Document Class and a Package for Handling Multi-File ...
file and several subsidiary files (subfiles) akin to the \input command, with ... In this process the rest of the document is of...
Read more >
Quick Start Guide - typegoose
type has to be defined when working with Arrays, because Reflection only ... Decorated schema configuration classes (like KittenClass above) must use ...
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