Skip to content
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

Drop FK constraint on media_obj in MediaDecisionThrough, update backfillmoderationdecision command #4530

Merged
merged 3 commits into from
Jun 24, 2024

Conversation

stacimc
Copy link
Contributor

@stacimc stacimc commented Jun 20, 2024

Fixes

Fixes #4512 by @krysal

Description

The backfillmoderationdecision management command creates backfilled ModerationDecision objects for existing MediaReports that have had some action taken on them (ie, not pending). The command was failing when encountering images that were deleted as part of a deindexed report, because the image no longer exists in the image table.

This PR resolves this by:

  • Dropping the foreign key constraint on media_obj in the AudioDecisionThrough and ImageDecisionThrough tables. A decision can still reference the record it acted upon by its identifier, even if that record no longer exists in the primary media table.
  • Updating the backfillmoderationdecision mgmt command to both access and set the plain value of the image identifier when creating the ImageDecisionThrough records, rather than attempting to use the image instance (which fails for deleted images).

Testing Instructions

Run just api/recreate.

Go to http://localhost:50280/admin/api/imagereport/ and create several new image reports:

  • One with status deindexed
  • One with status no_action
  • One with status mature_filtered
  • One with status pending

There is an issue at the moment where DeletedMedia & SensitiveMedia objects won't be automatically created for these reports. I manually made them by running just api/ipython and:

from api.models.image import Image, DeletedImage, SensitiveImage

# Using the `identifier` I selected for the image report with status deindexed
DeletedImage.objects.create(media_obj=Image.objects.get(identifier='2e22c7e7-58b7-486c-9df8-16e84c27478f')) 

# Using the `identifier` I selected for the image report with status mature_filtered
SensitiveImage.objects.create(media_obj=Image.objects.get(identifier='c296b69b-c8d7-4fc3-b820-a83de6138e0e'))

Verify in the admin that you can see the newly created DeletedImage/SensitiveImage object.

Now run the management command: just api/dj backfillmoderationdecision --no-dry-run --media-type image --moderator deploy

You should see 3 moderation decisions were created. Check them out in the admin and make sure they look as expected, and that the reports/images/decisions are all linked together appropriately. The image that was deindexed will appear empty in the admin, since the image does not exist:

Screenshot 2024-06-20 at 3 07 58 PM

However if you run just api/pgcli and actually inspect the ImageDecisionThrough table, you can see that it is set appropriately:

deploy@db:openledger> select * from api_imagedecisionthrough;
+----+-------------+--------------------------------------+
| id | decision_id | identifier                           |
|----+-------------+--------------------------------------|
| 1  | 1           | 2e22c7e7-58b7-486c-9df8-16e84c27478f |
| 2  | 2           | c296b69b-c8d7-4fc3-b820-a83de6138e0e |
| 3  | 3           | ba711b67-2cbe-487a-9feb-19d70accf912 |
+----+-------------+--------------------------------------+

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (./ov just catalog/generate-docs for catalog
    PRs) or the media properties generator (./ov just catalog/generate-docs media-props
    for the catalog or ./ov just api/generate-docs for the API) where applicable.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@stacimc stacimc added 🟧 priority: high Stalls work on the project or its dependents 🛠 goal: fix Bug fix 💻 aspect: code Concerns the software code in the repository 🧱 stack: api Related to the Django API migrations Modifications to Django migrations labels Jun 20, 2024
@stacimc stacimc self-assigned this Jun 20, 2024
@stacimc stacimc requested a review from a team as a code owner June 20, 2024 22:10
Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

LGTM 👍 This fix makes sense... and actually gets rid of an unnecessary query too (passing report.media_obj to the query set would load the media object in first, I think?)

Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Thanks for the very thorough testing instructions! This worked as expected locally, I'm glad the set of changes was so simple 🚀

@stacimc stacimc force-pushed the fix/moderation-decision-drop-fk-constraint branch from 5a83c4b to a082bce Compare June 24, 2024 17:27
@WordPress WordPress deleted a comment from github-actions bot Jun 24, 2024
api/api/models/audio.py Outdated Show resolved Hide resolved
@dhruvkb
Copy link
Member

dhruvkb commented Jun 24, 2024

This PR overlapped with mine (PR #4544), so I requested changes where we differed.

@WordPress WordPress deleted a comment from github-actions bot Jun 24, 2024
Copy link

This PR has migrations. Please rebase it before merging to ensure that conflicting migrations are not introduced.

@stacimc
Copy link
Contributor Author

stacimc commented Jun 24, 2024

Agreed. That shouldn't be necessary for the backfill but I can go ahead and squash it into this migration 👍

@stacimc stacimc requested a review from dhruvkb June 24, 2024 17:54
@stacimc stacimc merged commit 70d71b3 into main Jun 24, 2024
47 checks passed
@stacimc stacimc deleted the fix/moderation-decision-drop-fk-constraint branch June 24, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix migrations Modifications to Django migrations 🟧 priority: high Stalls work on the project or its dependents 🧱 stack: api Related to the Django API
Projects
Archived in project
4 participants