-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[WEB-2680] chore: updated queryset for soft delete #5844
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,9 +43,19 @@ class Meta: | |
abstract = True | ||
|
||
|
||
class SoftDeletionQuerySet(models.QuerySet): | ||
def delete(self, soft=True): | ||
if soft: | ||
return self.update(deleted_at=timezone.now()) | ||
else: | ||
return super().delete() | ||
Comment on lines
+46
to
+51
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. 💡 Codebase verification Potential Breaking Change Confirmed: Multiple The analysis identified numerous instances where Affected Files:
Please review these deletions to ensure they align with the intended behavior. 🔗 Analysis chainPotential Breaking Change: The To verify where This script searches for all occurrences of 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Find all usages of `delete()` on QuerySets that may be affected.
# Search for `.delete(` calls in Python files.
rg --type=python '\.delete\('
Length of output: 143 Script: #!/bin/bash
# Description: Find all usages of `delete()` on QuerySets in Python files.
# Search for `.delete(` calls in all `.py` files.
rg '\.delete\(' --type py
Length of output: 10502 Script: #!/bin/bash
# Description: Find all usages of `delete()` on QuerySets in Python files that do NOT specify `soft=False`.
# Search for `.delete(` calls not followed by `soft=False`.
rg '\.delete\((?!.*soft\s*=\s*False)' --type py
Length of output: 295 Script: #!/bin/bash
# Description: Find all usages of `delete()` on QuerySets in Python files that do NOT specify `soft=False`.
# Search for `.delete(` calls in all `.py` files and exclude lines with `soft=False`.
rg '\.delete\(' --type py | grep -v 'soft\s*=\s*False'
Length of output: 9254 |
||
|
||
|
||
class SoftDeletionManager(models.Manager): | ||
def get_queryset(self): | ||
return super().get_queryset().filter(deleted_at__isnull=True) | ||
return SoftDeletionQuerySet(self.model, using=self._db).filter( | ||
deleted_at__isnull=True | ||
) | ||
|
||
|
||
class SoftDeleteModel(models.Model): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -421,7 +421,7 @@ def update(self, instance, validated_data): | |
updated_by_id = instance.updated_by_id | ||
|
||
if assignees is not None: | ||
IssueAssignee.objects.filter(issue=instance).delete() | ||
IssueAssignee.objects.filter(issue=instance).delete(soft=False) | ||
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. Inconsistency with PR objective: Hard delete implemented instead of soft delete The changes in lines 424 and 441 are implementing a hard delete ( Consider the following points:
To align with the PR objective, consider changing IssueAssignee.objects.filter(issue=instance).delete() and IssueLabel.objects.filter(issue=instance).delete() Please verify if this aligns with the intended soft delete implementation across the project. Also applies to: 441-441 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. 💡 Codebase verification Soft delete implementation is inconsistent or missing in Our analysis reveals that the Consider the following points:
🔗 Analysis chainReconsider the use of hard delete for related entities The changes to use Consider the following points:
To align with the PR objectives and maintain data integrity, consider the following changes: - IssueAssignee.objects.filter(issue=instance).delete(soft=False)
+ IssueAssignee.objects.filter(issue=instance).delete() # This will use the default soft delete
- IssueLabel.objects.filter(issue=instance).delete(soft=False)
+ IssueLabel.objects.filter(issue=instance).delete() # This will use the default soft delete Additionally, ensure that the queryset used to fetch these related entities is updated to exclude soft-deleted records, if not already implemented. To confirm the current soft delete implementation, please run the following script: This script will help us understand the current soft delete implementation and ensure that our changes are consistent with the existing codebase. Also applies to: 441-441 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the soft delete implementation for IssueAssignee and IssueLabel models
# Check for a soft delete field (e.g., is_deleted, deleted_at) in the models
echo "Checking for soft delete fields in IssueAssignee and IssueLabel models:"
rg -A 5 "class (IssueAssignee|IssueLabel)\(" apiserver/plane/db/models/
# Check for custom manager implementation that might handle soft deletes
echo "\nChecking for custom manager implementations:"
rg -A 10 "class (IssueAssignee|IssueLabel)Manager\(" apiserver/plane/db/models/
# Check for any existing soft delete logic in views or serializers
echo "\nChecking for existing soft delete logic:"
rg "delete\(.*soft" apiserver/plane/
Length of output: 2863 |
||
IssueAssignee.objects.bulk_create( | ||
[ | ||
IssueAssignee( | ||
|
@@ -438,7 +438,7 @@ def update(self, instance, validated_data): | |
) | ||
|
||
if labels is not None: | ||
IssueLabel.objects.filter(issue=instance).delete() | ||
IssueLabel.objects.filter(issue=instance).delete(soft=False) | ||
IssueLabel.objects.bulk_create( | ||
[ | ||
IssueLabel( | ||
|
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.
Consider the implications of switching to hard delete
The changes from
delete()
todelete(soft=False)
forIssueAssignee
andIssueLabel
represent a shift from soft deletion to hard deletion. This modification has several important implications:Consider the following:
Would you like assistance in implementing any of these suggestions?
Also applies to: 221-221