Skip to content

[IMP] pydantic: moving from pydantic v1 to v2#551

Merged
OCA-git-bot merged 3 commits into
OCA:17.0from
petrus-v:17.0-pydantic-support-v2
Sep 17, 2025
Merged

[IMP] pydantic: moving from pydantic v1 to v2#551
OCA-git-bot merged 3 commits into
OCA:17.0from
petrus-v:17.0-pydantic-support-v2

Conversation

@petrus-v

@petrus-v petrus-v commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Smothly migrate webservice from pydantic<2.0 using pydantic odoo module to pydantic>2.0 getting the same behaviour retrieves odoo data from Odoo records.

Using this PR to migrate your pydantic models you have to do something this:

  • before using pydantic < "2.0" your model looks like something like this:
from pydantic import BaseModel

from odoo.addons.pydantic.utils import GenericOdooGetter


class PartnerModel(BaseModel):
    class Config:
        orm_mode = True
        getter_dict = GenericOdooGetter
    
    id: int
    name: str
  • after using pydantic > "2.0" you should subclass PydanticOdooBaseModel which set the pydantic model config with the new from_attributes=True (aka old orm_mode). Your model will get same behaviour as the previous versions using the GenericOdooGetter:
from odoo.addons.pydantic.utils import PydanticOdooBaseModel


class PartnerModel(PydanticOdooBaseModel):

    id: int
    name: str

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

@petrus-v
petrus-v force-pushed the 17.0-pydantic-support-v2 branch 4 times, most recently from c38ea04 to f67615e Compare July 29, 2025 00:35
@petrus-v petrus-v changed the title [IMP] pydantic: support to pydantic v2 and higher [IMP] pydantic: support to pydantic v1 and v2 Jul 29, 2025
@petrus-v
petrus-v force-pushed the 17.0-pydantic-support-v2 branch from f67615e to d592160 Compare July 29, 2025 00:52
@lmignon

lmignon commented Jul 29, 2025

Copy link
Copy Markdown
Contributor

@petrus-v Thank you for the PR. IMO it's not a good idea to try to keep the compatibility with pydantic 1. I'm not in favour of maintaining this support into OCA addon. Pydantic V1 is no more supported with fastapi, extendable_fastapi and a restriction is declared into the manifest file for these addons.

@petrus-v

Copy link
Copy Markdown
Contributor Author

@lmignon thanks for your feedback. I'm fine to drop the support to pydantic v1, at least I did it to write some unit test in the module to make sure serialisation behave in the same way. As far I understand your are not using the pydantic module in your v17.0 projects so we can drop the compatibility !

Let's do it !

@petrus-v
petrus-v force-pushed the 17.0-pydantic-support-v2 branch from 2f31fdf to 4c2a1a7 Compare July 29, 2025 07:31
@petrus-v

Copy link
Copy Markdown
Contributor Author

@lmignon et voilà : dropping support to pydantic v1 !

@petrus-v petrus-v changed the title [IMP] pydantic: support to pydantic v1 and v2 [IMP] pydantic: moving from pydantic v1 to v2 Jul 29, 2025
@petrus-v

Copy link
Copy Markdown
Contributor Author

@alexandregaldeano, @Koudja I would love to get your review on this one !

@lmignon lmignon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @petrus-v

@alexandregaldeano alexandregaldeano left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@lmignon

lmignon commented Aug 18, 2025

Copy link
Copy Markdown
Contributor

/ocabot merge minor

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 17.0-ocabot-merge-pr-551-by-lmignon-bump-minor, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Aug 18, 2025
Signed-off-by lmignon
@OCA-git-bot

Copy link
Copy Markdown
Contributor

@lmignon your merge command was aborted due to failed check(s), which you can inspect on this commit of 17.0-ocabot-merge-pr-551-by-lmignon-bump-minor.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@sebastienbeau sebastienbeau added this to the 17.0 milestone Sep 1, 2025
@petrus-v

petrus-v commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

@lmignon I've pushed a new commit that freeze graphql_server dependency to make the CI check pass to help resuming the merge process

Comment thread pydantic/utils.py Outdated
@petrus-v
petrus-v force-pushed the 17.0-pydantic-support-v2 branch from e5d5eed to d0e124b Compare September 11, 2025 13:29
@petrus-v
petrus-v force-pushed the 17.0-pydantic-support-v2 branch from 6ed824e to 8ce9331 Compare September 11, 2025 13:42
@petrus-v
petrus-v force-pushed the 17.0-pydantic-support-v2 branch from 8ce9331 to 79aba45 Compare September 11, 2025 14:25

@damdam-s damdam-s left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

works perfectly on custom project !
thanks !

@lmignon

lmignon commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

/ocabot merge minor

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 17.0-ocabot-merge-pr-551-by-lmignon-bump-minor, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit d949ca2 into OCA:17.0 Sep 17, 2025
7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at ed98446. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants