Skip to content
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
7 changes: 2 additions & 5 deletions src/sentry/deletions/defaults/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db.models import Q
from django.utils import timezone

from sentry.deletions.base import BaseRelation, ModelDeletionTask
from sentry.deletions.base import BaseRelation, ModelDeletionTask, ModelRelation
from sentry.models.files.file import File


Expand Down Expand Up @@ -37,8 +37,5 @@ def get_child_relations(self, instance: File) -> list[BaseRelation]:
from sentry.models.files.fileblobindex import FileBlobIndex

return [
BaseRelation(
params={"model": FileBlobIndex, "query": {"file_id": instance.id}},
task=None, # Use BulkModelDeletionTask
),
ModelRelation(FileBlobIndex, {"file_id": instance.id}),
]
4 changes: 2 additions & 2 deletions src/sentry/runner/commands/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def models_which_use_deletions_code_path() -> list[tuple[type[Model], str, str]]
(PullRequest, "date_added", "date_added"),
(RuleFireHistory, "date_added", "date_added"),
(Release, "date_added", "date_added"),
(File, "timestamp", "timestamp"),
(File, "timestamp", "id"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: The remove_cross_project_models function tries to remove a hardcoded tuple that was changed in this PR, causing a ValueError when cleanup --project is run.
Severity: HIGH | Confidence: 0.98

🔍 Detailed Analysis

The `cleanup` command will crash when run with the `--project` flag. A recent change updated the cleanup configuration for the `File` model from `(File, "timestamp", "timestamp")` to `(File, "timestamp", "id")`. However, the `remove_cross_project_models` function, which is called during project-specific cleanup, was not updated. It still attempts to remove the old, non-existent tuple `(File, "timestamp", "timestamp")` from a list. This operation will raise an unhandled `ValueError`, causing the entire cleanup command to fail and preventing any project-specific cleanup from completing.

💡 Suggested Fix

In remove_cross_project_models, update the line deletes.remove((File, "timestamp", "timestamp")) to deletes.remove((File, "timestamp", "id")) to match the new tuple structure defined elsewhere.

🤖 Prompt for AI Agent
Fix this bug. In src/sentry/runner/commands/cleanup.py at line 538: The `cleanup`
command will crash when run with the `--project` flag. A recent change updated the
cleanup configuration for the `File` model from `(File, "timestamp", "timestamp")` to
`(File, "timestamp", "id")`. However, the `remove_cross_project_models` function, which
is called during project-specific cleanup, was not updated. It still attempts to remove
the old, non-existent tuple `(File, "timestamp", "timestamp")` from a list. This
operation will raise an unhandled `ValueError`, causing the entire cleanup command to
fail and preventing any project-specific cleanup from completing.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member

Choose a reason for hiding this comment

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

It's actually right about this, although I don't know how much it actually matters

Copy link
Member Author

Choose a reason for hiding this comment

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

oh yea, no reason not to correct this, I will

(Commit, "date_added", "id"),
]

Expand All @@ -548,7 +548,7 @@ def remove_cross_project_models(

# These models span across projects, so let's skip them
deletes.remove((ArtifactBundle, "date_added", "date_added"))
deletes.remove((File, "timestamp", "timestamp"))
deletes.remove((File, "timestamp", "id"))
return deletes


Expand Down
Loading