-
Notifications
You must be signed in to change notification settings - Fork 113
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
[Spike] Clarifying Overlap: Pydantic Models vs. Data Classes in Backend #1538
Comments
Refactoring this ticket has proven to be challenging due to discrepancies between the Pydantic base classes in
@ravi-kumar-pilla @noklam @merelcht @antonymilne @tynandebold |
Thank you @antonymilne for the time. Based on the discussion today, I would like to follow what Antony mentioned -
@rashidakanchwala @noklam please add on anything if I missed. Thank you ! |
Some more context and notes - sorry for the delay in writing this up! When it comes to handling the responses, this is where things stand now:
I definitely think it's a good move to convert the data model to use Why should these things be separate in the first place? This gives some good principles, although in our case much of it is not relevant. In practice, for us, the main distinction between the data model and the API responses will be that the responses must be JSON serialisable while the data model can have arbitrary objects in it (e.g. an But the responses and data model will be very similar in kedro-viz, so while they should remain distinct there should be a good way to write them without just copying and pasting code. You should definitely read this page to understand the different options. Basically for us I think there's 3 options:
Overall I would start with one of the models (e.g. Just so it doesn't get forgotten: |
Description
We recently had a look at our backend structure while reviewing the Shareable Viz PR, we realised that using both Pydantic Base Models and data classes in our backend might be unnecessary. This ticket is to investigate this issue and refactor the code accordingly.
Context:
FastAPI's documentation recommends the use of Pydantic for input validation and data serialization. It mentions data classes offering a more advanced approach. Using both Pydantic models and data classes for similar purposes has lead to redundancy and has caused issues with mypy 1.0.
In this issue; we want to understand the below:-
Checklist
The text was updated successfully, but these errors were encountered: