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/upgrade pydantic v2 #354

Open
wants to merge 73 commits into
base: main
Choose a base branch
from
Open

Feat/upgrade pydantic v2 #354

wants to merge 73 commits into from

Conversation

alithethird
Copy link
Contributor

@alithethird alithethird commented Aug 27, 2024

Updated Pydantic version to v2.8.2

Overview

Rationale

Juju Events Changes

Module Changes

Library Changes

Checklist

@alithethird alithethird self-assigned this Aug 27, 2024
@alithethird alithethird added the enhancement New feature or request label Aug 27, 2024
Copy link
Collaborator

@javierdelapuente javierdelapuente left a comment

Choose a reason for hiding this comment

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

Added a few comments

@@ -407,12 +403,12 @@ class CharmConfig(BaseModel):
"""

denylist: list[FirewallEntry]
dockerhub_mirror: AnyHttpsUrl | None
dockerhub_mirror: AnyHttpsUrl | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to add a default value?

labels: tuple[str, ...]
openstack_clouds_yaml: OpenStackCloudsYAML | None
openstack_clouds_yaml: OpenStackCloudsYAML | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to add a default value?

path: GitHubPath
reconcile_interval: int
repo_policy_compliance: RepoPolicyComplianceConfig | None
repo_policy_compliance: RepoPolicyComplianceConfig | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to add a default value?

@@ -486,8 +483,6 @@ def _parse_openstack_clouds_config(cls, charm: CharmBase) -> OpenStackCloudsYAML
openstack_clouds_yaml: OpenStackCloudsYAML = yaml.safe_load(
cast(str, openstack_clouds_yaml_str)
)
# use Pydantic to validate TypedDict.
create_model_from_typeddict(OpenStackCloudsYAML)(**openstack_clouds_yaml)
Copy link
Collaborator

Choose a reason for hiding this comment

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

IINM, this raises if the input dict does not match the typedict, so there is a change in functionality. I see in pydantic 2 something similar https://docs.pydantic.dev/2.3/usage/types/dicts_mapping/#typeddict (not sure if appropriate as it says that for python < 3.12 you may need a library)

src/charm.py Outdated
@@ -1182,8 +1182,9 @@ def _on_image_relation_joined(self, _: ops.RelationJoinedEvent) -> None:
return

clouds_yaml = state.charm_config.openstack_clouds_yaml
cloud = list(clouds_yaml["clouds"].keys())[0]
auth_map = clouds_yaml["clouds"][cloud]["auth"]
# unsubscriptable-object / thinks cloud_yaml is kind of a list
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at charm_config it is OpenStackCloudsYAML | None, so it probably thinks it can be None, which it can be....

@@ -496,15 +492,15 @@ def _parse_openstack_clouds_config(cls, charm: CharmBase) -> OpenStackCloudsYAML

try:
openstack_cloud.initialize(openstack_clouds_yaml)
except OpenStackInvalidConfigError as exc:
except (OpenStackInvalidConfigError, TypeError) as exc:
Copy link
Collaborator

Choose a reason for hiding this comment

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

the linter has found something strange after the change in:

    openstack_clouds_yaml: OpenStackCloudsYAML | None
    openstack_clouds_yaml: OpenStackCloudsYAML | None = None

if not proxy_address.port
else f"{proxy_address.host}:{proxy_address.port}"
)
if "http" in proxy_address.host:
Copy link
Collaborator

Choose a reason for hiding this comment

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

is http or https in the host?

@@ -194,7 +194,7 @@ def create_runner(self, registration_token: str) -> InstanceId:
instance_id=instance_id,
image=self._server_config.image,
flavor=self._server_config.flavor,
network=self._server_config.network,
network=str(self._server_config.network) if self._server_config.network else None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

testing locally I do not need the change.

@canonical canonical deleted a comment from github-actions bot Oct 16, 2024
Copy link
Contributor

Test coverage for 368b7e6

Name                         Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------------------
src/charm.py                   613    160    138     26    70%   243-245, 311-330, 348-350, 351->355, 381-385, 464, 471-473, 494-499, 516-522, 543, 555-561, 576-577, 596-597, 606, 611, 641-642, 644->653, 648->653, 658-664, 698, 702-707, 758-763, 772->775, 798-810, 814-815, 843-870, 883-888, 907-917, 932-934, 981-982, 984-985, 987-988, 1067->1069, 1134-1135, 1173-1175, 1183-1189, 1267-1299, 1313-1318, 1333-1367, 1371
src/charm_state.py             461     19     82      3    95%   274-286, 510-514, 636-637, 692-693, 1128->1131, 1135-1136, 1183, 1196-1197
src/errors.py                   25      0      0      0   100%
src/event_timer.py              52      6      0      0    88%   105-106, 143-144, 160-161
src/firewall.py                 51     18     10      0    67%   42-43, 66-69, 111-185
src/github_client.py            23      2      4      0    93%   71-72
src/logrotate.py                43      0      2      0   100%
src/lxd_type.py                 35      0      0      0   100%
src/runner_manager_type.py      39      0      0      0   100%
src/runner_type.py              39      0      0      0   100%
src/shared_fs.py                93     17     10      1    83%   52-53, 120-121, 146-147, 155-156, 162-163, 181, 184-185, 197-198, 241-242
src/utilities.py                32      4      6      2    79%   66-69, 111
------------------------------------------------------------------------
TOTAL                         1506    226    252     32    83%

Static code analysis report

Run started:2024-10-16 04:10:51.789917

Test results:
  No issues identified.

Code scanned:
  Total lines of code: 4982
  Total lines skipped (#nosec): 2
  Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 6

Run metrics:
  Total issues (by severity):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
  Total issues (by confidence):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
Files skipped (0):

@cbartz
Copy link
Collaborator

cbartz commented Nov 14, 2024

@alithethird Is this still worked on?

@alithethird
Copy link
Contributor Author

Currently not working on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed Libraries: Out of sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants