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

Don't munge types in Docker registry config values. #21649

Merged

Conversation

benjyw
Copy link
Contributor

@benjyw benjyw commented Nov 14, 2024

We document a schema for the registries dict, including
specifying that certain fields should be bool-valued.

I see no need to coerce those values into bools if they
were actually strings, especially since we don't document
that we do that (AFAICT).

We should require users to adhere to the published schema.
If this "breaks" users, well, they were accidentally relying on
unadvertised leniency, and the fix is extremely easy.

Note that this coercion was very ad hoc. We don't apply it
uniformly across all fields in the docker registry config,
and we certainly don't do this in other dict-valued options
across the repo.

This gets rid of a spurious dependency of the Docker backend
on internal code of the legacy options parser.

@benjyw benjyw added the category:internal CI, fixes for not-yet-released features, etc. label Nov 14, 2024
@benjyw benjyw requested a review from kaos November 14, 2024 21:50
@benjyw benjyw force-pushed the no_type_munging_in_docker_registry_options branch from b08c71e to 2b88f41 Compare November 15, 2024 01:00
extra_image_tags=tuple(
d.get("extra_image_tags", DockerRegistryOptions.extra_image_tags)
),
repository=Parser.to_value_type(d.get("repository"), str, None),
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 was particularly unnecessary, since all that function does when you pass str as the type is cast...

@benjyw
Copy link
Contributor Author

benjyw commented Nov 15, 2024

To clarify, I think using the wrong type is a potential sign of larger error, and we shouldn't be attempting to coerce input types. We can validate them, perhaps, but that is a separate thing, and a pretty arbitrary one.

@@ -52,13 +51,13 @@ def from_dict(cls, alias: str, d: dict[str, Any]) -> DockerRegistryOptions:
return cls(
alias=alias,
address=d["address"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that we never validated the type (or presence) of d["address"] for example. I prefer to be uniformly strict than have some arbitrary semi-validation that follows no rhyme or reason.

@benjyw benjyw merged commit e3d7222 into pantsbuild:main Nov 15, 2024
24 checks passed
@benjyw benjyw deleted the no_type_munging_in_docker_registry_options branch November 15, 2024 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:internal CI, fixes for not-yet-released features, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants