Skip to content
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

feat: Support Pydantic 1 and 2 within the same application #2487

Merged
merged 29 commits into from Oct 27, 2023

Conversation

provinzkraut
Copy link
Member

@provinzkraut provinzkraut commented Oct 22, 2023

Description

Support Pydantic 1 and 2 by making use of its backwards compatibility layer; Pydantic 2 ships with version 1 in the pydantic.v1 namespace. This allows us to support either both 1 & 2 if version 2 is installed or just version 1 if version 1 is installed.

In addition, this also simplifies our testing setup somewhat, as we can test for both Pydantic 1 & 2 without having to re-install dependencies.

Closes

Closes #2419

Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
…refactored) (#2489)

'Refactored by Sourcery'

Co-authored-by: Sourcery AI <>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Copy link
Member

@guacs guacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't gone through all of it yet.

litestar/_openapi/schema_generation/schema.py Show resolved Hide resolved
litestar/contrib/pydantic/pydantic_dto_factory.py Outdated Show resolved Hide resolved
litestar/contrib/pydantic/pydantic_init_plugin.py Outdated Show resolved Hide resolved
litestar/contrib/pydantic/pydantic_schema_plugin.py Outdated Show resolved Hide resolved
litestar/contrib/pydantic/utils.py Outdated Show resolved Hide resolved
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Copy link
Contributor

@peterschutt peterschutt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge effort! LGTM.

My only concern is we aren't actually testing anywhere with actual v1.10 installed and v2 not installed. What do you think about making another acceptance test that tests a light pydantic v1 only application alongside our minimal app test in the publish CI? Just to trap any major stuff like import errors before a release?

litestar/contrib/pydantic/pydantic_init_plugin.py Outdated Show resolved Hide resolved
litestar/contrib/pydantic/pydantic_schema_plugin.py Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
Copy link
Member

@guacs guacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good, but it's probably best if someone else took a look this as well just to make sure we don't miss anything.

litestar/_openapi/schema_generation/schema.py Show resolved Hide resolved
litestar/contrib/pydantic/pydantic_schema_plugin.py Outdated Show resolved Hide resolved
litestar/contrib/pydantic/utils.py Outdated Show resolved Hide resolved
litestar/typing.py Show resolved Hide resolved
provinzkraut and others added 9 commits October 23, 2023 17:52
Co-authored-by: Peter Schutt <peter.github@proton.me>
Co-authored-by: Peter Schutt <peter.github@proton.me>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
@provinzkraut provinzkraut enabled auto-merge (squash) October 27, 2023 17:02
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
@provinzkraut
Copy link
Member Author

This PR will bring down coverage a bit, as a lot of previously uncovered code will now be included in the coverage report. This should be addressed, but I didn't want to blow up this PR even more.

@sonarcloud
Copy link

sonarcloud bot commented Oct 27, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug B 1 Bug
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

93.9% 93.9% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@github-actions
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2487

@provinzkraut provinzkraut merged commit 5db8d81 into main Oct 27, 2023
16 of 17 checks passed
@provinzkraut provinzkraut deleted the pydantic-v1-v2 branch October 27, 2023 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Support Pydantic 1 and 2 within the same app
3 participants