-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix: model list schema constraints error when using Pydantic V1 #131
Fix: model list schema constraints error when using Pydantic V1 #131
Conversation
It seems pydantic v1 uses |
Maybe we need to add a custom |
Thank you @yanyongyu for the fast response and for maintaining this library. I've tried your proposal of changing the kwarg name to I understand that this is sub-optimal as we are effectively not respecting the JSON schema but I see no other option as the models have ForwardReferences that will break the implementation in V1. Fortunatly, V2 will be unaffected. |
i see the comments in the code. this issue has occured before when using pydantic v1, and was fixed when pydantic v2 released. i will change the comments to describe the problem better. |
I will add some test cases later. |
What's being fixed
As a user of Pydantic V1, there are some models that use constraints on Pydantic List fields that fail on import:
Reproduction steps
On the root of the project, with the venv populated and activated:
Solution
To palliate this issue, a ternary operator might be injected on the Pydantic
Field
constructor to disable or enable the constraints depending on the library version:from githubkit.compat import PYDANTIC_V2 annotations: Missing[ List[ReposOwnerRepoCheckRunsPostBodyPropOutputPropAnnotationsItems] ] = Field( - max_length=50, default=UNSET, description='Adds information from your analysis to specific lines of code. Annotations are visible on GitHub in the **Checks** and **Files changed** tab of the pull request. The Checks API limits the number of annotations to a maximum of 50 per API request. To create more than 50 annotations, you have to make multiple requests to the [Update a check run](https://docs.github.com/rest/checks/runs#update-a-check-run) endpoint. Each time you update the check run, annotations are appended to the list of annotations that already exist for the check run. GitHub Actions are limited to 10 warning annotations and 10 error annotations per step. For details about how you can view annotations on GitHub, see "[About status checks](https://docs.github.com/articles/about-status-checks#checks)".', )
from githubkit.compat import PYDANTIC_V2 annotations: Missing[ List[ReposOwnerRepoCheckRunsPostBodyPropOutputPropAnnotationsItems] ] = Field( + max_length=50 if PYDANTIC_V2 else None, default=UNSET, description='Adds information from your analysis to specific lines of code. Annotations are visible on GitHub in the **Checks** and **Files changed** tab of the pull request. The Checks API limits the number of annotations to a maximum of 50 per API request. To create more than 50 annotations, you have to make multiple requests to the [Update a check run](https://docs.github.com/rest/checks/runs#update-a-check-run) endpoint. Each time you update the check run, annotations are appended to the list of annotations that already exist for the check run. GitHub Actions are limited to 10 warning annotations and 10 error annotations per step. For details about how you can view annotations on GitHub, see "[About status checks](https://docs.github.com/articles/about-status-checks#checks)".', )