Skip to content

Conversation

@vbrodsky
Copy link
Contributor

@vbrodsky vbrodsky commented Feb 8, 2024

Story: https://labelbox.atlassian.net/browse/PLT-145

Please review for background and implementation approach: https://labelbox.atlassian.net/wiki/spaces/~63d753c8724a5c79c7b69a36/pages/2369257507/SDK+Pydantic2+Pydantic1+Compatibility

This PR introduces several crucial updates aimed at enhancing our sdk compatibility with Pydantic2. The changes are as follows:

  • Implementation of a Pydantic Compatibility Module: This is the centerpiece of the PR. The module is designed to facilitate our future usage of Pydantic v1 up to transition to Pydantic v2 or some other DTO implementation
  • Updates to All Files Utilizing Pydantic: These changes are captured in the commit 2611b38. Given the comprehensive nature of our test automation tools, I believe manual review of each file for Pydantic-related updates is unnecessary. Our automated tests are robust enough to ensure that the updates meet our quality standards without requiring manual inspection of every change.
  • Removal of Pydantic v2 Restriction: We have eliminated the restriction on Pydantic v2 from both requirements.txt and setup.py.

@vbrodsky vbrodsky requested review from a team, adrian-chang and apollonin February 8, 2024 22:15
@vbrodsky vbrodsky force-pushed the VB/support-pydantic2_PLT-145 branch 5 times, most recently from 84e4c3b to 04de631 Compare February 9, 2024 19:44
@vbrodsky vbrodsky force-pushed the VB/support-pydantic2_PLT-145 branch from 04de631 to 779f692 Compare February 13, 2024 01:32
@vbrodsky vbrodsky force-pushed the VB/support-pydantic2_PLT-145 branch from 444d092 to f592269 Compare February 13, 2024 01:36

# Check if the version is 1
if pydantic_version.startswith("1"):
pydantic_v1_module_name = "pydantic" if sub_module_path is None else f"pydantic.{sub_module_path}"
Copy link
Contributor

@sfendell-labelbox sfendell-labelbox Feb 13, 2024

Choose a reason for hiding this comment

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

I think this is more legible and DRY if we don't have nested boolean statements here, e.g.

If sub_module_path:
    pydantic_v1_module_name = f"pydantic.{submodulepath}"
else if pydantic_version.startswith("1"):
   pydantic_v1_module_name = ...
else:
   ...

if pydantic_version.startswith("1"):
pydantic_v1_module_name = "pydantic" if sub_module_path is None else f"pydantic.{sub_module_path}"
else: # use pydantic 2 v1 thunk
pydantic_v1_module_name = "pydantic.v1" if sub_module_path is None else f"pydantic.{sub_module_path}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would assume we want pydantic.v1 in both cases. If so, why not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well what if users are still using pydantic v1? Currently we need to support this case so we will do from pydantic instead of from pydantic.v1

Copy link
Contributor

@mrobers1982 mrobers1982 Feb 13, 2024

Choose a reason for hiding this comment

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

I thought that case is captured by the if condition?

I'm referring to the f"pydantic.{sub_module_path}" in the else condition which assumes the usage of Pydantic 2.x.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

Copy link
Contributor

@mrobers1982 mrobers1982 left a comment

Choose a reason for hiding this comment

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

Good start!

@vbrodsky vbrodsky merged commit f997496 into develop Feb 13, 2024
@vbrodsky vbrodsky deleted the VB/support-pydantic2_PLT-145 branch February 13, 2024 21:40
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.

4 participants