Refactors "set_fields" routine with custom context manager#112
Merged
DrPaulSharp merged 2 commits intoRascalSoftware:mainfrom Jan 9, 2025
Merged
Refactors "set_fields" routine with custom context manager#112DrPaulSharp merged 2 commits intoRascalSoftware:mainfrom
DrPaulSharp merged 2 commits intoRascalSoftware:mainfrom
Conversation
alexhroom
approved these changes
Jan 9, 2025
RATapi/classlist.py
Outdated
Comment on lines
268
to
269
| # Pydantic is installed, so set up a context manager that will | ||
| # suppress validation errors until all fields have been set. |
Collaborator
There was a problem hiding this comment.
Suggested change
| # Pydantic is installed, so set up a context manager that will | |
| # suppress validation errors until all fields have been set. | |
| # Pydantic is installed, so set up a context manager that will | |
| # suppress custom validation errors until all fields have been set. |
Comment on lines
320
to
325
|
|
||
| if pydantic_object: | ||
| self._class_handle.model_validate(self.data[index]) |
Collaborator
There was a problem hiding this comment.
i think this needs a code comment for why we're revalidating (i.e. "to catch any actual validation issues")
Collaborator
Author
There was a problem hiding this comment.
I've gone for
# We have suppressed custom validation errors for pydantic objects.
# We now must revalidate the pydantic model outside the validation context
# to catch any errors that remain after setting all of the fields.
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 PR adds a context manager to the
set_fieldsroutine that should suppress errors in custom validation (i.e., field validators and model validators that we write) for pydantic models included within a ClassList.