Skip to content

Update DynamicFieldsEnum to include all deprecated fields #17409

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

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tests/unit/forklift/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pytest

from packaging.version import Version
from sqlalchemy.dialects.postgresql import ENUM
from webob.multidict import MultiDict

from warehouse.forklift import metadata
Expand Down Expand Up @@ -283,7 +284,20 @@ def test_valid_dynamic(self):

def test_invalid_dynamic(self):
data = MultiDict(metadata_version="2.2", name="spam", version="2.0")
data.add("dynamic", "Requires")
data.add("dynamic", "Invalid")
with pytest.raises(ExceptionGroup) as excinfo:
metadata.parse(None, form_data=data)
_assert_invalid_metadata(excinfo.value, "dynamic")

def test_valid_dynamic_but_missing_from_our_enum(self, monkeypatch):
"""
Handles the case where there are new metadata fields that pypa/packaging
considers to be valid, but don't exist in our enum and would otherwise fail
when inserting them into the database
"""
monkeypatch.setattr(metadata, "DynamicFieldsEnum", ENUM())
data = MultiDict(metadata_version="2.2", name="spam", version="2.0")
data.add("dynamic", "author")
with pytest.raises(ExceptionGroup) as excinfo:
metadata.parse(None, form_data=data)
_assert_invalid_metadata(excinfo.value, "dynamic")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Update DynamicFieldsEnum to include all deprecated fields

Revision ID: 24aa37164e72
Revises: ed4cc2ef6b0f
Create Date: 2025-01-14 15:19:26.813044
"""

from alembic import op
from alembic_postgresql_enum import ColumnType, TableReference

revision = "24aa37164e72"
down_revision = "ed4cc2ef6b0f"


def upgrade():
op.sync_enum_values(
enum_schema="public",
enum_name="release_dynamic_fields",
new_values=[
"Platform",
"Supported-Platform",
"Summary",
"Description",
"Description-Content-Type",
"Keywords",
"Author",
"Author-Email",
"Maintainer",
"Maintainer-Email",
"License",
"License-Expression",
"License-File",
"Classifier",
"Requires-Dist",
"Requires-Python",
"Requires-External",
"Project-Url",
"Provides-Extra",
"Provides-Dist",
"Obsoletes-Dist",
"Home-Page",
"Download-Url",
"Requires",
"Provides",
"Obsoletes",
],
affected_columns=[
TableReference(
table_schema="public",
table_name="releases",
column_name="dynamic",
column_type=ColumnType.ARRAY,
)
],
enum_values_to_rename=[],
)


def downgrade():
op.sync_enum_values(
enum_schema="public",
enum_name="release_dynamic_fields",
new_values=[
"Platform",
"Supported-Platform",
"Summary",
"Description",
"Description-Content-Type",
"Keywords",
"Home-Page",
"Download-Url",
"Author",
"Author-Email",
"Maintainer",
"Maintainer-Email",
"License",
"License-Expression",
"License-File",
"Classifier",
"Requires-Dist",
"Requires-Python",
"Requires-External",
"Project-Url",
"Provides-Extra",
"Provides-Dist",
"Obsoletes-Dist",
],
affected_columns=[
TableReference(
table_schema="public",
table_name="releases",
column_name="dynamic",
column_type=ColumnType.ARRAY,
)
],
enum_values_to_rename=[],
)
10 changes: 8 additions & 2 deletions warehouse/packaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,6 @@ class ReleaseURL(db.Model):
"Description",
"Description-Content-Type",
"Keywords",
"Home-Page",
"Download-Url",
"Author",
"Author-Email",
"Maintainer",
Expand All @@ -564,6 +562,14 @@ class ReleaseURL(db.Model):
"Provides-Extra",
"Provides-Dist",
"Obsoletes-Dist",
# Although the following are deprecated fields, they are technically
# permitted as dynamic by PEP 643
# https://github.com/pypa/setuptools/issues/4797#issuecomment-2589514950
"Home-Page",
"Download-Url",
"Requires",
"Provides",
"Obsoletes",
name="release_dynamic_fields",
)

Expand Down