Skip to content

Conversation

@gerrod3
Copy link
Contributor

@gerrod3 gerrod3 commented Oct 27, 2025

Prep work for PEP 740. I noticed there were new fields to implement: https://docs.pypi.org/api/upload/. The serializer ignores fields we don't list and technically we don't need these fields to perform the upload, they are just a nice sanity check. Currently of the required fields name, version and pyversion I am not doing any extra validation. We get the values by extracting the metadata from the artifact in the upload task so hard to validate in the request serializer.

@gerrod3 gerrod3 force-pushed the more-twine-upload-fields branch 3 times, most recently from 88c8488 to 1a0c240 Compare October 30, 2025 17:26
min_length=64,
max_length=64,
)
protocol_version = serializers.IntegerField(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would not it be better to use ChoiceField instead of IntegerField with min and max values?

Comment on lines +95 to +83
if filetype := data.get("filetype"):
if filetype != packagetype:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe if (filetype := data.get("filetype")) and filetype != packagetype: to save one nesting?

@jobselko
Copy link
Contributor

I think this is worthy of the changelog - minimally because of the validations.

version = serializers.CharField(
help_text=_("Version of the package."),
required=False,
)
Copy link
Contributor

@dralley dralley Nov 10, 2025

Choose a reason for hiding this comment

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

edit: maybe I'm misunderstanding, I suppose you mention that the values do come from the uploaded artifact, but the RPM plugin also does so and doesn't add any of the metadata to the upload serializer, so this is different than what I'm familiar with.

I'm confused about the fact that all of it seems to be optional. If it's all optional than why allow the user to specify in the first place (maybe these are all just gripes with the API they've chosen and not with the fact that Pulp needs to implement it)

Is it just the case that twine provides all this information on uploads and the API (including e.g. warehouse) is meant to just trust it unconditionally, if provided? Or does it get verified? And if it gets verified then against what, and why bother with accepting it if there's a canonical source?

Seems like it would be ideal for most of these details to be parsed from package metadata instead of provided alongside the upload? (though IIRC that was briefly discussed earlier, I guess my point is that if we add it now would it not become useless should metadata later be parsed directly from the package). But again maybe this is just complaining about the API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, maybe I should remove them. Reading the PyPI code (https://github.com/pypi/warehouse/blob/117eafc3739f738a2c29fbadbb858bf502ba1ff0/warehouse/forklift/legacy.py#L618-L623) it seems they trust all the metadata that is posted in the request, but we have always been extracting the metadata from the file so these fields are kind of useless.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, what is the resolution, stay or remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're gone, look at the latest push.

@gerrod3 gerrod3 force-pushed the more-twine-upload-fields branch 2 times, most recently from 8f4f288 to 077993f Compare November 11, 2025 20:10
@gerrod3 gerrod3 force-pushed the more-twine-upload-fields branch from 077993f to ea1dc16 Compare November 11, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants