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

Validate dataclass with optional field and default #2

Closed
wants to merge 1 commit into from

Conversation

kennyworkman
Copy link
Member

>>> @dataclass(frozen=True)
... class MAuth:
...     token: str
...     notebook_id: str
...     user_id: Optional[str] = None
a = {'notebook_id': '204', 'token': 'Latch-Session-Token dba3dcf605337e67fa1a3d55bf220637'}
>>> untraced_validate(a, MAuth)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/kenny/latch/plots-faas/.venv/lib/python3.12/site-packages/latch_data_validation/data_validation.py", line 177, in untraced_validate
    raise DataValidationError(
latch_data_validation.data_validation.DataValidationError:
Dataclass did not match schema:
  Missing fields:
      - 'user_id'
  {'notebook_id': '204', 'token': 'Latch-Session-Token dba3dcf605337e67fa1a3d55bf220637'}
  did not match
  <class '__main__.MAuth'>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant