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

Upgrade to pydantic v2 #141

Merged
merged 17 commits into from
Jun 11, 2024
Merged

Upgrade to pydantic v2 #141

merged 17 commits into from
Jun 11, 2024

Conversation

oscarbc96
Copy link
Contributor

No description provided.

@oscarbc96 oscarbc96 changed the title wip WIP: pydantic2 May 11, 2024
@oscarbc96 oscarbc96 changed the title WIP: pydantic2 Upgrade to pydantic v2 May 11, 2024
@oscarbc96 oscarbc96 marked this pull request as ready for review May 11, 2024 08:08
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

ResolvableDateOrList,
ResolvableDatetimeOrList,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes the order due to the new lax config of pydantic. Date can be parsed inside a Datetime

Copy link
Member

Choose a reason for hiding this comment

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

It might be a good idea to add a comment mentioning this as it won't be obvious going forward

Copy link
Contributor

Choose a reason for hiding this comment

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

Added

@@ -23,12 +23,6 @@ class Resource(CustomModel):
UpdatePolicy: Optional[Dict] = None
UpdateReplacePolicy: Optional[ResolvableStr] = None

@validator("Type")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been replaced by a Discriminated Union



class GenericResource(Resource):
"""This class is used for all resource types that don't have a dedicated class."""

ALLOW_EXISTING_TYPES: ClassVar[bool] = True
Type: str
Type: Optional[str] = None # Optional to handle cases like "AWS::CloudFormation::Authentication"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ignaciobolonio Review this case

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any issue with this as long as it has retrocompatibility

ignaciobolonio
ignaciobolonio previously approved these changes May 11, 2024
Copy link
Contributor

@ignaciobolonio ignaciobolonio left a comment

Choose a reason for hiding this comment

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

There are a LOT of changes but it follows a similar way to my attempt here https://github.com/Skyscanner/pycfmodel/tree/update_pydantic_v2 It is amazing work Oscar, great contribution



class GenericResource(Resource):
"""This class is used for all resource types that don't have a dedicated class."""

ALLOW_EXISTING_TYPES: ClassVar[bool] = True
Type: str
Type: Optional[str] = None # Optional to handle cases like "AWS::CloudFormation::Authentication"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any issue with this as long as it has retrocompatibility

xavi-bean
xavi-bean previously approved these changes May 13, 2024
@@ -34,9 +34,9 @@ def _expand_actions(actions: Union[str, List[str]], not_action=False) -> List[st
def expand_actions(obj):
if isinstance(obj, dict):
for key, value in obj.items():
if key == "Action":
if key == "Action" and value is not None:
Copy link
Member

@jsoucheiron jsoucheiron May 15, 2024

Choose a reason for hiding this comment

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

Suggested change
if key == "Action" and value is not None:
if value is None:
continue # or obj[key] = None
elif key == "Action":

Otherwise we'll end up recursively calling expand actions. I'm not sure if that's what we want, but in any case it should change the current behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done


from pycfmodel.model.base import FunctionDict


class LooseIPv4Network(_BaseNetwork):
class LooseIPv4Network:
__slots__ = ()
Copy link
Member

Choose a reason for hiding this comment

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

why do we want slots here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to make it more efficient, we don't want to store anything in memory

@@ -78,15 +135,19 @@ def validate(cls, value: Any) -> bool:

ResolvableIPv4Network = Resolvable[LooseIPv4Network]
ResolvableIPv6Network = Resolvable[LooseIPv6Network]
ResolvableIPvXNetwork = Annotated[
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ResolvableIPvXNetwork = Annotated[
ResolvableIPNetwork = Annotated[

Copy link
Contributor

Choose a reason for hiding this comment

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

Done

setup.py Outdated
@@ -28,7 +28,7 @@

setup(
name="pycfmodel",
version="0.22.0",
version="0.23.0",
Copy link
Member

Choose a reason for hiding this comment

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

We need a major here

Copy link
Contributor

Choose a reason for hiding this comment

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

agree, and updated to 1.0.0

* Add boolean coercion to string

* Minor fixes

* Minor fixes

* Update cf actions
@oscarbc96 oscarbc96 dismissed stale reviews from xavi-bean and ignaciobolonio via 5e3114b May 22, 2024 13:23
setup.py Outdated Show resolved Hide resolved
ignaciobolonio and others added 2 commits June 7, 2024 09:49
Co-authored-by: Jordi Soucheiron <[email protected]>
Copy link
Member

@jsoucheiron jsoucheiron left a comment

Choose a reason for hiding this comment

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

Fantastic work!

@jsoucheiron jsoucheiron merged commit f72f4ed into Skyscanner:master Jun 11, 2024
4 checks passed
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.

5 participants