Skip to content

Replace typedload#316

Open
mandopaloooza wants to merge 3 commits intomainfrom
replace-typedload
Open

Replace typedload#316
mandopaloooza wants to merge 3 commits intomainfrom
replace-typedload

Conversation

@mandopaloooza
Copy link
Copy Markdown
Collaborator

Description

  • Replace typedload with cattrs

Checklist

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR replaces the typedload-based entity (de)serialization implementation with cattrs, updates Python dependency pins accordingly, and bumps the Helm chart/app versions to reflect the change.

Changes:

  • Replace typedload loader/dumper logic with cattrs.Converter-based structuring/unstructuring in appgate/attrs.py.
  • Update dependency inputs/locks to remove typedload and add cattrs.
  • Bump Helm chart version and appVersion from 0.5.0 to 0.5.1 for both CRD and operator charts.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
requirements.in Swap typedload for cattrs as a direct dependency.
requirements.txt Lock cattrs and remove typedload from the compiled requirements.
k8s/operator/Chart.yaml Bump chart/app versions to 0.5.1.
k8s/crd/Chart.yaml Bump chart/app versions to 0.5.1.
appgate/attrs.py Rework entity dump/load to use cattrs and custom hooks/exceptions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +36 to +39
AppgateLoadException = getattr(
openapi_types,
"Appgate" + "Typed" + "loadException",
)
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

AppgateLoadException is being obtained via getattr(openapi_types, "Appgate" + "Typed" + "loadException"), which hides the dependency from static analysis/type checking and will fail at import time with an AttributeError if the symbol ever changes. Prefer a direct import/alias (e.g., import AppgateTypedloadException as AppgateLoadException) so linters and type checkers can validate it and refactors are safer.

Copilot uses AI. Check for mistakes.
def parse_datetime(value: Any) -> datetime.datetime:
try:
# dateutil.fromisofromat cannot handle string that contains 6+ sub-second digits
# dateutil.fromisofromat cannot handle strings that contain 6+ sub-second digits
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The comment mentions dateutil.fromisofromat, which is misspelled and also not the API being used here (parser.isoparse). Please correct the wording to avoid confusion (likely referring to datetime.fromisoformat’s limitations with >6 fractional digits).

Suggested change
# dateutil.fromisofromat cannot handle strings that contain 6+ sub-second digits
# Use dateutil.parser.isoparse because datetime.fromisoformat cannot
# handle strings that contain more than 6 sub-second digits.

Copilot uses AI. Check for mistakes.
Comment on lines 147 to 151
elif strict:
raise AppgateTypedloadException(
raise AppgateLoadException(
"Unable to dump entity: name/id field is missing",
platform_type=PlatformType.K8S,
)
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

k8s_dumper is used for both K8S and GIT dumping (see get_dumper), but the exception hard-codes platform_type=PlatformType.K8S. This will mislabel errors raised while dumping for the Git platform. Consider passing the caller’s platform_type into k8s_dumper (or selecting the appropriate PlatformType when raising).

Copilot uses AI. Check for mistakes.
Comment on lines +203 to 208
dumper: Callable[
[Entity_T, bool, Dict[str, List[MissingFieldDependencies]] | None],
Dict[str, Any],
]

if platform_type in {PlatformType.K8S, PlatformType.GIT}:
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

When api_spec is missing for PlatformType.GIT, this raises AppgateLoadException(..., platform_type=PlatformType.K8S), which reports the wrong platform in logs/error handling. Use the actual platform_type value (K8S vs GIT) when constructing the exception.

Copilot uses AI. Check for mistakes.
Comment on lines 279 to +282
if (read_only and platform_type == PlatformType.K8S) or (
write_only
and platform_type
in {
PlatformType.APPGATE,
PlatformType.GIT,
}
write_only and platform_type in {PlatformType.APPGATE, PlatformType.GIT}
):
# Don't load attribute from K8S in read only mode even if
# Don't load attribute from K8S in read-only mode even if
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

This branch is dead code (pass) and can be removed. If it’s meant to enforce/track required fields, implement that logic (or rely on structure_attrs_fromdict raising a clear error) rather than leaving an empty conditional.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants