Skip to content

Allow custom Defaults to raise exceptions for conditional defaults #108

@binaryDiv

Description

@binaryDiv

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovements to existing features or smaller new featuresnew featureNew feature that is not (only) a validator class

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions