-
-
Notifications
You must be signed in to change notification settings - Fork 732
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: Upgrade to Pydantic V2 #3134
feat: Upgrade to Pydantic V2 #3134
Conversation
@property | ||
def db_url(self) -> str: | ||
host = f"{self.POSTGRES_SERVER}:{self.POSTGRES_PORT}" | ||
return PostgresDsn.build( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PostgresDsn changes, pretty sure this is right
@@ -47,6 +46,25 @@ def _cbv(router: APIRouter, cls: type[T], *urls: str, instance: Any | None = Non | |||
return cls | |||
|
|||
|
|||
# copied from Pydantic V1 Source: https://github.com/pydantic/pydantic/blob/1c91c8627b541b22354b9ed56b9ef1bb21ac6fbd/pydantic/v1/typing.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gross copy from Pydantic V1
@@ -0,0 +1,252 @@ | |||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied from Pydantic V1. I wasn't sure where to put it so I put it in schema/_mealie
I tried to highlight some of the bigger changes in the comments, but this PR is pretty massive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. This was such a huge lift. Thanks for taking this on.
I'll give you $50 if you didn't break anything 😉
Optimistic |
In mealie v1.3.0, the dependency on pydantic was bumped from v1 to v2: mealie-recipes/mealie#3134 Thus the workaround for using pydantic v1 can be removed.
* authlib was required in v1.4.0 (mealie-recipes/mealie#3280) * pillow-heif was required in v1.5.0 (mealie-recipes/mealie#3409) * pydantic-settings was required in v1.3.0 (mealie-recipes/mealie#3134 - same PR as pydantic v2 bump) * pyjwt was required in v1.6.0 (mealie-recipes/mealie#3521)
What type of PR is this?
(REQUIRED)
What this PR does / why we need it:
(REQUIRED)
This PR is a monster. Pydantic provides a tool to make some model changes (
bump-pydantic
), but it doesn't cover most things. Thankfully, their migration guide covers just about everything, save for some of the grosser stuff: https://docs.pydantic.dev/latest/migration/Most changes are pretty straightforward, but there are a few... "special" changes that are a bit hacky:
is_classvar
for this, but that doesn't exist anymore. Rather than attempt to figure out how that part of the codebase works, I just copied it over from Pydantic V1datetime_parse
module/method to handle this. I tried using a recommended substitution, but got different results than we were expecting (timezones were getting mishmashed somewhere and tests were failing) so I, again, just copied Pydantic V1's implementationGetterDict
isn't a thing anymore, so all of our custom getter-dicts had to be replaced. I basically replaced them with field validators (Pydantic V2's replacement for@validator
), and fixed some other edgecases (particularly withGroup
/User.group
being the group name)Also, Somehow the format for
PostgresDsn
changed. I had to tweak it to get postgres to work right, but if you could take a look and make sure I didn't screw that up, that'd be great.Which issue(s) this PR fixes:
(REQUIRED)
N/A, will close some renovate bot PRs