fixed: View model creation fails from non-ORM contexts for models with synthetic properties #631
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request focuses on improving the robustness and clarity of the Pydantic view models and their data transformations in the codebase. The main changes ensure that "synthetic" fields (fields generated from ORM objects) are only populated when the relevant ORM attributes are present, preventing errors during model instantiation. Additionally, the handling of publication/source fields is standardized to always expect lists (not Optionals), and exception handling is made more consistent and informative.
This addresses an inconsistency where responses from API routes were unable to recreate the model that they were validated against prior to being returned by the server.
Pydantic Model Robustness and Data Transformation:
user_associations,score_sets,experiments,publication_identifier_associations, etc.), reducing the risk of attribute errors when creating models from non-ORM data. [1] [2] [3] [4] [5]AttributeErrorandKeyError, and updated error messages to be more descriptive about coercion failures rather than missing attributes. [1] [2] [3] [4]Publication/Source Field Standardization:
ScoreCalibrationBase,ScoreCalibrationModify,ScoreCalibrationCreate,SavedScoreCalibration,ScoreCalibration, etc.) so thatthreshold_sources,classification_sources, andmethod_sourcesare always required lists (not Optionals), ensuring consistency in API responses and internal data structures. [1] [2] [3] [4]Nonevalues.These changes collectively improve the reliability of data ingestion and transformation in the API and make error reporting more actionable for developers.