-
Notifications
You must be signed in to change notification settings - Fork 2
fixed: View model creation fails from non-ORM contexts for models with synthetic properties #631
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
Merged
bencap
merged 9 commits into
release-2025.6.0
from
bugfix/bencap/597/view-model-creation-fails-from-non-db-contexts
Jan 23, 2026
Merged
fixed: View model creation fails from non-ORM contexts for models with synthetic properties #631
bencap
merged 9 commits into
release-2025.6.0
from
bugfix/bencap/597/view-model-creation-fails-from-non-db-contexts
Jan 23, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jstone-dev
approved these changes
Jan 21, 2026
4388e0e to
a59bafe
Compare
- Only generate synthetic fields for experiments (e.g., publication identifiers, score set URNs) when ORM attributes are present, avoiding dict-based synthesis. - Validators now check for ORM attribute presence before transformation, ensuring correct behavior for both ORM and API/dict contexts. - Updated tests to expect Pydantic validation errors when required synthetic fields are missing.
- Refactored SavedTargetGene and TargetGeneWithScoreSetUrn to synthesize synthetic fields (e.g., external_identifiers, score_set_urn) only from ORM objects, not dicts. - Updated model validators to require either target_sequence or target_accession for all construction contexts. - Added tests to ensure SavedTargetGene and TargetGeneWithScoreSetUrn can be created from both ORM (attributed object) and non-ORM (dict) contexts.
- Refactored SavedCollection and CollectionWithUrn to ensure robust handling of synthetic and required fields for both ORM and dict contexts. - Added parameterized tests to verify all key attributes are correctly handled in both construction modes. - Added tests for creation from both dict and ORM contexts, mirroring the approach used for other models.
- Refactored MappedVariant view models to ensure robust handling of synthetic and required fields for both ORM and dict contexts. - Added tests to verify all key attributes and synthetic properties are correctly handled in both construction modes. - Ensured creation from both dict and ORM contexts, mirroring the approach used for other models.
- Refactored Variant view models to ensure robust handling of synthetic and required fields for both ORM and dict contexts. - Added tests to verify all key attributes and synthetic properties are correctly handled in both construction modes. - Ensured creation from both dict and ORM contexts, mirroring the approach used for other models.
- Refactored ScoreCalibration view models to ensure robust handling of synthetic and required fields for both ORM and dict contexts. - Made the source fields non-optional to enforce required data integrity. - Added tests to verify all key attributes and synthetic properties are correctly handled in both construction modes. - Ensured creation from both dict and ORM contexts, mirroring the approach used for other models.
- Refactored ScoreSet view models to ensure robust handling of synthetic and required fields for both ORM and dict contexts. - Added tests to verify all key attributes and synthetic properties are correctly handled in both construction modes. - Ensured creation from both dict and ORM contexts, mirroring the approach used for other models.
92e9abb to
ff8f8ee
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.