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

DefaultValueNotFoundError for Optional fields #241

Open
eroller opened this issue Aug 8, 2023 · 0 comments
Open

DefaultValueNotFoundError for Optional fields #241

eroller opened this issue Aug 8, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@eroller
Copy link

eroller commented Aug 8, 2023

Is your feature request related to a problem? Please describe.
There is no way to require a field that is of type Optional, because dacite gives it a default value (i.e. None) automatically. See https://github.com/konradhalas/dacite#optional-fields

Describe the solution you'd like
A way to configure dacite to require fields which have an Optional type.

Describe alternatives you've considered
I cannot think of a workaround to get a DefaultValueNotFoundError when converting a dictionary that has missing fields of an Optional type.

Additional context
It feels like dacite should provide a mechanism to distinguish between these two dataclasses. Currently they both behave the same way and this is inconsistent compared to dataclasses where the fields are not of Optional type.

@dataclass
class MyRequiredFieldsThatMayHaveValueNone:
   name: str | None
@dataclass
class MyOptionsFieldsThatByDefaultHaveValueNone:
   name: str | None = None
@eroller eroller added the enhancement New feature or request label Aug 8, 2023
@eroller eroller changed the title MissingValueError for Optional fields DefaultValueNotFoundError for Optional fields Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant