Skip to content
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 custom Defaults to raise exceptions for conditional defaults #108

Open
binaryDiv opened this issue Nov 1, 2023 · 0 comments
Open
Labels
enhancement Improvements to existing features or smaller new features new feature New feature that is not (only) a validator class
Milestone

Comments

@binaryDiv
Copy link
Contributor

Currently, if a custom Default class raises an exception, this exception would not be handled.

A potential use case for this are "conditional defaults": Having a field that is required under certain (external) conditions, but has a default otherwise. The Default object would either return a default value or raise an exception if the field is supposed to be required.

Proposal: The DataclassValidator should catch specific exceptions when filling in default values and treat them as "this field is required". However, this should not allow just any exception. There should be either a specific new exception for this usecase (NoDefaultException?), or the DictRequiredFieldError should be used.

@binaryDiv binaryDiv added enhancement Improvements to existing features or smaller new features new feature New feature that is not (only) a validator class labels Nov 1, 2023
@binaryDiv binaryDiv added this to the 1.0.0 Release milestone Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features or smaller new features new feature New feature that is not (only) a validator class
Projects
None yet
Development

No branches or pull requests

1 participant