fix: Discriminatory Union types not working after migration to Pydantic v2#31
Merged
fix: Discriminatory Union types not working after migration to Pydantic v2#31
Conversation
…ic v2 - Updated docstring formatting in multiple model files to remove leading indentation. - Reorganized and formatted field definitions for better clarity in `CommonConversationDto`, `ProviderReference`, `QACheckDtoV2`, `SegmentWarning`, and `UserDetailsDtoV3`. - Changed discriminator property names from double underscores to single underscores for consistency across models. - Enhanced error messages in the `from_dict` and `from_json` methods to provide clearer context on failures. - Applied consistent formatting for enum validation logic in field validators. - Removed unnecessary comments and improved overall code structure for maintainability.
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
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 refactors several model files in the
phrasetms_clientpackage to improve code readability and consistency, particularly around discriminator handling and field definitions. The main changes involve renaming internal discriminator variables, formatting field definitions for clarity, and updating the logic for discriminator-based deserialization. These updates make the codebase easier to maintain and less error-prone.Discriminator Handling and Serialization Logic
__discriminator_property_name,__discriminator_value_class_map) are renamed to use a single underscore prefix (e.g.,_discriminator_property_name) for consistency and clarity acrossabstract_analyse_settings_dto.py,abstract_connector_dto.py, andabstract_project_dto.py. The logic for accessing these variables is updated to use.defaultfor safer attribute access. [1] [2] [3]from_jsonandfrom_dictmethods are rewritten to use explicit string type hints and improved formatting for union types, enhancing readability and maintainability. Error messages in these methods are also updated to reference the new discriminator variable names. [1] [2] [3]Field Definition Formatting
abstract_analyse_settings_dto.py,abstract_connector_dto.py, andabstract_project_dto.py. [1] [2] [3]Import and Style Consistency
These changes collectively enhance the maintainability, clarity, and reliability of the model classes in the codebase.- Updated docstring formatting in multiple model files to remove leading indentation.
CommonConversationDto,ProviderReference,QACheckDtoV2,SegmentWarning, andUserDetailsDtoV3.from_dictandfrom_jsonmethods to provide clearer context on failures.