-
Notifications
You must be signed in to change notification settings - Fork 240
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
Allow callables for 'default' in schema (and minor fixes) #200
Conversation
there's no need for child-validators to achieve that. to access the whole context it requires the possibility to use methods as callables. i will probably do a code review this evening in europe. |
here are my thoughts:
can circular dependencies be detected while schema validation? if yes, that would be preferable since it's easier to deal with errors prior to validation in client code and the document processing itself would be more lightweight. |
I love this. Detecting circular dependencies during schema validation would be great. |
You're right, I'm going to change this. The initial thought was to enforce a situation where
Thanks for pointing to the Checking for circular dependencies during schema validation sounds good, but I'm afraid that will cover only "simple" cases (but those are probably the most common ones). I'd leave the error handling in |
another thought: why check for circular references at all? if such occurs, it's completely the developer's responsibility, right? i'm very much for anticipating user's mistakes, but i think developers can be left with their own fate when it becomes too complex to protect them from themselves. and there are certainly more potential mistakes a developer could make than circular references. so, essentially: every developer should test her/his code well. |
oh, and a reason why it should be an extra rule when using callables to /set/ a value: one may actually want to set a callable /as/ value.
have fun! i think it should be easy to adapt from the ’rename_*’ rules. i'd say ’default_setter’ would be a meaningful name.
|
8ab265b
to
620c10e
Compare
Awesome. Thank you. |
You're fast - this wasn't meant to be merged right away :). This is what the (wip) = (work in progress) should indicate. Sorry for the confusion! I'd like to remove the commented out test at least and maybe add some comments for clarification, shall I open another Pull Request? |
ah sorry about that. yup open another pr. |
Allows the use of computed default values via callables / lambda functions. For an example why this is useful, see https://github.com/nicolaiarocci/eve/pull/815.
This implementation is slightly different (and simpler) than the one in the pull request mentioned above, as here only the current (sub)document is passed to the callable. Passing the whole document seemed unnecessarily complex as in that case we would have to take care of the evaluation order of child validators, too. The downside is, of course, that you can only access fields in your current "nesting level".