-
Notifications
You must be signed in to change notification settings - Fork 212
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
Add backfillmoderationdecision
management command
#4415
Conversation
cb2d606
to
c6c6d4b
Compare
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.
Left a comment with just some fiddly ORM details, but if the number of non-pending reports in production is low enough, it probably won't even matter.
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.
In my tests, for both Image and Audio reports with the status "mature_filtered" did not get their action set to "confirmed_sensitive" as I expected (both had an empty action) 🤔 Are you able to reproduce that, @krysal?
@stacimc I do get the "confirmed_sensitive" action for a "mature_filtered" report. What output for the command do you get? |
3daf454
to
4d97b12
Compare
@krysal I don't see any MediaDecisionThrough being created when I run this. The decisions are created, but not the through table records. I thought this would happen automatically, but it doesn't. What's more, it isn't possible to set it directly on the media, it needs to be handled through diff --git a/api/api/management/commands/backfillmoderationdecision.py b/api/api/management/commands/backfillmoderationdecision.py
index f88e40769..e9340604a 100644
--- a/api/api/management/commands/backfillmoderationdecision.py
+++ b/api/api/management/commands/backfillmoderationdecision.py
@@ -5,7 +5,7 @@ from django.contrib.auth import get_user_model
from django_tqdm import BaseCommand
from api.constants.moderation import DecisionAction
-from api.models import AudioDecision, AudioReport, ImageDecision, ImageReport
+from api.models import AudioDecision, AudioReport, ImageDecision, ImageReport, ImageDecisionThrough, AudioDecisionThrough
from api.models.media import DMCA, MATURE_FILTERED, NO_ACTION, PENDING
@@ -43,9 +43,11 @@ class Command(BaseCommand):
MediaReport = ImageReport
MediaDecision = ImageDecision
+ MediaDecisionThrough = ImageDecisionThrough
if media_type == "audio":
MediaReport = AudioReport
MediaDecision = AudioDecision
+ MediaDecisionThrough = AudioDecisionThrough
non_pending_reports = MediaReport.objects.filter(decision=None).exclude(
status=PENDING
@@ -83,6 +85,15 @@ class Command(BaseCommand):
for report, decision in zip(reports_chunk, decisions):
report.decision = decision
MediaReport.objects.bulk_update(reports_chunk, ["decision"])
+ MediaDecisionThrough.objects.bulk_create(
+ [
+ MediaDecisionThrough(
+ media_obj_id=report.media_obj_id,
+ decision_id=report.decision_id,
+ )
+ for report in reports_chunk
+ ]
+ )
t.update(1)
t.info( |
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.
LGTM except for the issue with the decision through table, which I've described in a comment. Otherwise this is working fine when I test it, I did not have the issue Staci saw and explicitly made sure a decision was created in that case. However, I wonder if Staci is seeing an issue in Django admin caused by the lack of the decision through? Not sure what the downstream effects are currently of a missing decision through row for a media object.
I'll hold off on reviewing this PR till you've had a chance to address @sarayourfriend's requests for changes. The relationship between the media object and the decision can be created more succinctly using this decision.media_objs.add(media_obj) where openverse/api/api/admin/media_report.py Lines 443 to 468 in 2da7be1
|
The problem with doing it through the decision is that you have to go one-by-one, there's no way to make it a bulk operation; hence why I suggested In other cases, where a single decision is being created for multiple media objects, then yes, setting it on the decision (or media) instance is more straightforward and doesn't require manually creating the through table instances. In this case, though, we should use bulk create, in line with the rest of the code. |
9ac7591
to
6358bd7
Compare
6358bd7
to
df449e4
Compare
@sarayourfriend Good catch! I think the bulk updates of MediaDecision skip the MediaDecisionThrough table/model. Thanks for the handy diff, the changes have been applied. |
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.
LGTM! No longer seeing issues with confimed_sensitive
. I checked all action types and double checked the relationships are all set correctly, looks great 👍
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.
LGTM!
Fixes
Fixes #3641 by @sarayourfriend
Description
This PR adds the command as described in the implementation plan section for Deprecating and removing report status. It takes as options the media type, the username of the moderator (in production it should be
opener
but in local we usedeploy
) and a flag for whether to run the command or just get the count of report to process.Verify that the mapping is according to the specification.
Testing Instructions
To test manually, create some reports, mark them with a
reason
other than "pending" and run the command.Checklist
Update index.md
).main
) or a parent feature branch.just catalog/generate-docs
for catalogPRs) or the media properties generator (
just catalog/generate-docs media-props
for the catalog or
just api/generate-docs
for the API) where applicable.Developer Certificate of Origin
Developer Certificate of Origin