-
Notifications
You must be signed in to change notification settings - Fork 124
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
Simplify subrepo deletion #3343
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Simplified subrepo deletion logic to make it more reliable. |
33 changes: 33 additions & 0 deletions
33
pulp_rpm/app/migrations/0058_alter_addon_repository_alter_variant_repository.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 4.2.7 on 2023-11-29 23:12 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("core", "0114_remove_task_args_remove_task_kwargs"), | ||
("rpm", "0057_rpmpublication_checksum_type_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="addon", | ||
name="repository", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.RESTRICT, | ||
related_name="addons", | ||
to="core.repository", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="variant", | ||
name="repository", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.RESTRICT, | ||
related_name="variants", | ||
to="core.repository", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
from logging import getLogger | ||
|
||
from django.db import models | ||
from django.db.models.signals import post_delete | ||
from django.db.models.signals import pre_delete, post_delete | ||
from django.dispatch import receiver | ||
|
||
from pulpcore.plugin.models import ( | ||
|
@@ -107,8 +107,8 @@ def repositories(self): | |
""" | ||
from pulp_rpm.app.models import RpmRepository | ||
|
||
repo_ids = list(self.addons.values_list("repository__pk", flat=True)) | ||
repo_ids += list(self.variants.values_list("repository__pk", flat=True)) | ||
repo_ids = list(self.addons.values_list("repository_id", flat=True)) | ||
repo_ids += list(self.variants.values_list("repository_id", flat=True)) | ||
return RpmRepository.objects.filter(pk__in=repo_ids) | ||
|
||
def content(self): | ||
|
@@ -255,7 +255,7 @@ class Addon(BaseModel): | |
distribution_tree = models.ForeignKey( | ||
DistributionTree, on_delete=models.CASCADE, related_name="addons" | ||
) | ||
repository = models.ForeignKey(Repository, on_delete=models.PROTECT, related_name="addons") | ||
repository = models.ForeignKey(Repository, on_delete=models.RESTRICT, related_name="addons") | ||
|
||
class Meta: | ||
unique_together = ( | ||
|
@@ -317,7 +317,7 @@ class Variant(BaseModel): | |
DistributionTree, on_delete=models.CASCADE, related_name="variants" | ||
) | ||
repository = models.ForeignKey( | ||
Repository, on_delete=models.PROTECT, related_name="variants", null=True | ||
Repository, on_delete=models.RESTRICT, related_name="variants", null=True | ||
) | ||
|
||
class Meta: | ||
|
@@ -331,19 +331,19 @@ class Meta: | |
) | ||
|
||
|
||
@receiver(post_delete, sender=Addon) | ||
@receiver(post_delete, sender=Variant) | ||
def cleanup_subrepos(sender, instance, **kwargs): | ||
@receiver(pre_delete, sender=DistributionTree) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
def setup_cleanup_subrepos(sender, instance, **kwargs): | ||
""" | ||
Find subrepos when a DistributionTree is being removed. | ||
""" | ||
Remove subrepos when a DistributionTree is being removed. | ||
repos = instance.repositories() | ||
instance.repositories = lambda: repos.all() | ||
|
||
|
||
@receiver(post_delete, sender=DistributionTree) | ||
def cleanup_subrepos(sender, instance, **kwargs): | ||
""" | ||
Delete the found subrepos of the deleted DistributionTree. | ||
""" | ||
subrepo = None | ||
try: | ||
subrepo = instance.repository | ||
except Repository.DoesNotExist: | ||
pass | ||
if subrepo: | ||
Variant.objects.filter(repository=subrepo).delete() | ||
Addon.objects.filter(repository=subrepo).delete() | ||
subrepo.delete() | ||
repos = instance.repositories() | ||
repos.delete() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍