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

make Platform class serializable for workunit-logger #21792

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

Conversation

cburroughs
Copy link
Contributor

@cburroughs cburroughs commented Dec 20, 2024

As described in #21773, having the Helm backend lint with the workunit-logger results in json serialization errors. Giving Platform a string representation resolves this (and anywhere else we may want to "print" it.

Example workunit:

{"name": "pants.backend.helm.util_rules.tool.download_external_helm_plugin", "span_id": "bdaa19a5cd1ef797", "level": "DEBUG", "parent_id": "c8c137a5b78f02ea", "start_secs": 1734722271, "start_nanos": 296631921, "duration_secs": 0, "duration_nanos": 51846519, "description": "Download external Helm plugin", "metadata": {"name": "unittest", "version": "0.3.3", "platform": "linux_x86_64"}}

NOTE: I think this is a totally safe ~one line change, but admit it is to a rather core class.

fixes #21773

As described in pantsbuild#21773, having the Helm backend lint with the
workunit-logger results in json serialization errors.  Giving `Platform`
a string representation resolves this (and anywhere else we may want
to "print" it.

Example workunit:
```
{"name": "pants.backend.helm.util_rules.tool.download_external_helm_plugin", "span_id": "bdaa19a5cd1ef797", "level": "DEBUG", "parent_id": "c8c137a5b78f02ea", "start_secs": 1734722271, "start_nanos": 296631921, "duration_secs": 0, "duration_nanos": 51846519, "description": "Download external Helm plugin", "metadata": {"name": "unittest", "version": "0.3.3", "platform": "linux_x86_64"}}
```

NOTE: I think this is a totally safe one line change, but admit it is
to a rather core class.
@cburroughs cburroughs added this to the 2.24.x milestone Dec 20, 2024
@cburroughs cburroughs self-assigned this Dec 20, 2024
@@ -39,7 +39,9 @@ def current_platform(
if env_tgt.val.has_field(DockerPlatformField):
return Platform(env_tgt.val[DockerPlatformField].normalized_value)
if env_tgt.val.has_field(RemotePlatformField):
return Platform(env_tgt.val[RemotePlatformField].value)
remote_platform = env_tgt.val[RemotePlatformField].value
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am very confused:

  • Why mypy was satisfied with this before since I think Enum behaves the same way.
  • Why it neede dso much extra help with the remote_platform var callout instead of just a check on .value.

This is to resolve:

Partition #2 - python-default, ['CPython==3.11.*']:
src/python/pants/engine/internals/platform_rules.py: note: In function "current_platform":
src/python/pants/engine/internals/platform_rules.py:42:29: error: Argument 1 to "Platform" has incompatible type "str | None"; expected "str"  [arg-type]
              return Platform(env_tgt.val[RemotePlatformField].value)
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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 understand it either, but I have seen mypy get confused about this sort of thing elsewhere at times.

@cburroughs cburroughs marked this pull request as ready for review December 20, 2024 21:02
@cburroughs cburroughs removed this from the 2.24.x milestone Dec 21, 2024
@cburroughs
Copy link
Contributor Author

(Removing 2.24.x as I woke up this morning remembering that StrEnum was only added in 3.11)

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.

json serialization error for work units of linting helm charts
2 participants