Skip to content

fix: delete_at not updating#6577

Merged
sriramveeraghanta merged 1 commit intopreviewfrom
fix-deleted-at-not-updating
Feb 12, 2025
Merged

fix: delete_at not updating#6577
sriramveeraghanta merged 1 commit intopreviewfrom
fix-deleted-at-not-updating

Conversation

@sangeethailango
Copy link
Member

@sangeethailango sangeethailango commented Feb 10, 2025

Description

If an issue is archived or drafted, deleted_at was not getting updated and this PR will fix the it.

Summary by CodeRabbit

  • Refactor
    • Improved the handling of related records during soft deletion. This update standardizes cascading removal operations by refining the way associated data is processed, contributing to enhanced reliability and a more predictable deletion experience. End users may experience improved data consistency when removing items, with fewer unexpected disruptions and overall seamless processing.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2025

Walkthrough

This pull request updates the soft_delete_related_objects function in the deletion task module by modifying how related objects are fetched. The function now specifies the "objects" manager when retrieving related objects. The change is localized to the queryset retrieval without affecting the logic handling different on_delete behaviors or the recursive deletion process.

Changes

File Path Change Summary
apiserver/plane/bgtasks/deletion_task.py Updated soft_delete_related_objects to retrieve related objects via getattr(instance, related_name)(manager="objects").all() instead of the previous call.

Possibly related PRs

Suggested labels

⚙️backend

Suggested reviewers

  • pablohashescobar

Poem

I'm just a rabbit hopping through code,
Updating queries along the data road.
With "objects" manager now in place,
My soft deletion sets a brisk new pace.
Hop along, developers, and enjoy this code!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
apiserver/plane/bgtasks/deletion_task.py (4)

85-88: LGTM! The change fixes the deleted_at update issue.

The modification to use manager="objects" ensures that the correct queryset manager is used when fetching related objects, which should resolve the issue where deleted_at was not being updated for epics.

However, consider adding debug logging to track the deletion process:

     related_queryset = getattr(instance, related_name)(
         manager="objects"
     ).all()
+    print(f"Fetched {related_queryset.count()} related objects for {related_name}")

101-103: Enhance error handling with structured logging.

Replace the basic print statement with proper logging to help with debugging and monitoring.

-                print(f"Error handling relation {related_name}: {str(e)}")
+                import logging
+                logger = logging.getLogger(__name__)
+                logger.error(
+                    "Error handling relation during soft delete",
+                    extra={
+                        "relation": related_name,
+                        "instance_type": type(instance).__name__,
+                        "instance_id": instance.pk,
+                        "error": str(e)
+                    },
+                    exc_info=True
+                )

112-114: Consider implementing the restore_related_objects function.

The function is currently empty but might be needed for restoring soft-deleted objects. Would you like me to help implement this function to complement the soft deletion functionality?


142-220: Refactor repetitive hard deletion code.

The hard deletion code has a lot of repetition. Consider refactoring it to use a more maintainable approach.

+    def delete_old_records(model):
+        return model.all_objects.filter(
+            deleted_at__lt=timezone.now() - timezone.timedelta(days=days)
+        ).delete()
+
+    models_to_delete = [
+        Workspace, Project, Cycle, Module, Issue, Page, IssueView,
+        Label, State, IssueActivity, IssueComment, IssueLink,
+        IssueReaction, UserFavorite, ModuleIssue, CycleIssue,
+        Estimate, EstimatePoint
+    ]
+
+    for model in models_to_delete:
+        _ = delete_old_records(model)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce57c14 and 15f4d2a.

📒 Files selected for processing (1)
  • apiserver/plane/bgtasks/deletion_task.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)

@sangeethailango sangeethailango marked this pull request as draft February 10, 2025 12:33
@sangeethailango sangeethailango self-assigned this Feb 10, 2025
@sangeethailango sangeethailango marked this pull request as ready for review February 10, 2025 14:16
@sriramveeraghanta sriramveeraghanta merged commit 6157d57 into preview Feb 12, 2025
19 of 22 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-deleted-at-not-updating branch February 12, 2025 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants