Skip to content

Commit e941ee0

Browse files
committed
Fix description field clash with base class
Assisted by: Claude Sonnet 4
1 parent 92fdd88 commit e941ee0

4 files changed

Lines changed: 37 additions & 10 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removed `description` field from models subclassing `Distribution` to fix field clash error when using pulpcore>=3.106.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Generated manually to migrate description fields from subclasses to parent Distribution class
2+
3+
from django.db import migrations
4+
5+
6+
def migrate_description_data_forward(apps, schema_editor):
7+
Distribution = apps.get_model("core", "Distribution")
8+
ContainerDistribution = apps.get_model("container", "ContainerDistribution")
9+
ContainerPullThroughDistribution = apps.get_model(
10+
"container", "ContainerPullThroughDistribution"
11+
)
12+
13+
for Model in (ContainerDistribution, ContainerPullThroughDistribution):
14+
for dist in Model.objects.all():
15+
if dist.description:
16+
parent = Distribution.objects.get(pk=dist.pk)
17+
if not parent.description:
18+
parent.description = dist.description
19+
parent.save(update_fields=["description"])
20+
21+
22+
class Migration(migrations.Migration):
23+
24+
dependencies = [
25+
# Ensure parent field exists before copying data
26+
("core", "0146_distribution_description"),
27+
("container", "0047_containernamespace_pulp_labels"),
28+
]
29+
30+
operations = [
31+
# Copy description data from subclass tables to parent Distribution table
32+
migrations.RunPython(migrate_description_data_forward, migrations.RunPython.noop),
33+
# Remove duplicate fields from subclasses
34+
migrations.RemoveField(model_name="containerdistribution", name="description"),
35+
migrations.RemoveField(model_name="containerpullthroughdistribution", name="description"),
36+
]

pulp_container/app/models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,6 @@ class ContainerPullThroughDistribution(Distribution, AutoAddObjPermsMixin):
834834
"Defaults to unrestricted pull access."
835835
),
836836
)
837-
description = models.TextField(null=True)
838837

839838
class Meta:
840839
default_related_name = "%(app_label)s_%(model_name)s"
@@ -878,7 +877,6 @@ class ContainerDistribution(Distribution, AutoAddObjPermsMixin):
878877
"Defaults to unrestricted pull access."
879878
),
880879
)
881-
description = models.TextField(null=True)
882880

883881
pull_through_distribution = models.ForeignKey(
884882
ContainerPullThroughDistribution,

pulp_container/app/serializers.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,6 @@ class ContainerDistributionSerializer(DistributionSerializer, GetOrCreateSeriali
421421
view_name="pulp_container/namespaces-detail",
422422
help_text=_("Namespace this distribution belongs to."),
423423
)
424-
description = serializers.CharField(
425-
help_text=_("An optional description."), required=False, allow_null=True
426-
)
427424
repository_version = RepositoryVersionRelatedField(
428425
required=False, help_text=_("RepositoryVersion to be served"), allow_null=True
429426
)
@@ -487,7 +484,6 @@ class Meta:
487484
"remote",
488485
"namespace",
489486
"private",
490-
"description",
491487
)
492488

493489

@@ -521,9 +517,6 @@ class ContainerPullThroughDistributionSerializer(DistributionSerializer):
521517
queryset=models.ContainerDistribution.objects.all(),
522518
required=False,
523519
)
524-
description = serializers.CharField(
525-
help_text=_("An optional description."), required=False, allow_null=True
526-
)
527520

528521
def validate(self, data):
529522
validated_data = super().validate(data)
@@ -549,7 +542,6 @@ class Meta:
549542
"distributions",
550543
"namespace",
551544
"private",
552-
"description",
553545
)
554546

555547

0 commit comments

Comments
 (0)