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

Defer the tags_list for media models #1029

Merged
merged 3 commits into from
Mar 28, 2023
Merged

Defer the tags_list for media models #1029

merged 3 commits into from
Mar 28, 2023

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Mar 26, 2023

Fixes

Related to #704 by @obulat

Description

This is the first step of the three-step process we need to follow to remove the tags_list from the database for zero-downtime deployments. This PR adds a custom Manager to the AbstractMedia model that prevents querysets from trying to access tags_list field as part of the model.

After this PR is deployed, we will need to drop the tags_list column from the database.

After the column is dropped, we can deploy the PR #956 that removes the tags_list field from the models and adds corresponding migrations. Note: the CustomManager needs to be removed from #956, otherwise we get an error when it is trying to defer the tags_list field that doesn't exist.

Testing Instructions

Run just up and search for something (http://localhost:50280/v1/images/?q=cat). In the logs (run just logs web or use the Docker UI to view the openverse-web-1 logs), you should see a log line with SELECT query that does not have tags_list:

2023-03-26 21:04:00 [2023-03-26 18:04:00,636 - django.db.backends - 131][DEBUG] 
[5caaae77211340c0a6a0cd568d8e9ec3] (0.014) SELECT "image"."id", "image"."created_on", "image"."updated_on", "image"."identifier", "image"."foreign_identifier", "image"."title", "image"."foreign_landing_url", "image"."creator", "image"."creator_url", "image"."thumbnail", "image"."provider", "image"."url", "image"."filesize", "image"."filetype", "image"."watermarked", "image"."license", "image"."license_version", "image"."source", "image"."last_synced_with_source", "image"."removed_from_source", "image"."view_count", "image"."tags", "image"."category", "image"."meta_data", "image"."width", "image"."height", "api_matureimage"."created_on", "api_matureimage"."identifier" FROM "image" LEFT OUTER JOIN "api_matureimage" ON ("image"."identifier" = "api_matureimage"."identifier") WHERE "image"."identifier" IN (UUID('3b858852-67df-44e1-8d57-683991d3ec67'), ...)); alias=default

If you do the same on main, you should see that the query does contain tags_list (see logs in this comment)

Checklist

  • My pull request has a descriptive title (not a vague title like
    Update 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.

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.

@obulat obulat added 🟨 priority: medium Not blocking but should be addressed soon 💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🧱 stack: api Related to the Django API labels Mar 26, 2023
@obulat obulat requested a review from a team as a code owner March 26, 2023 18:09
@obulat obulat requested review from AetherUnbound and dhruvkb March 26, 2023 18:09
@github-actions
Copy link

github-actions bot commented Mar 26, 2023

Full-stack documentation: Ready

https://WordPress.github.io/openverse/_preview/1029

Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.

You can check the GitHub pages deployment action list to see the current status of the deployments.

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.

LGTM! Just one suggestion regarding the name of the custom manager class, but that's non-blocking.

api/catalog/api/models/media.py Outdated Show resolved Hide resolved
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, but big +1 to Madison's suggestion for a clearer name for the manager.

I think you can drop the "custom" from the name as well: that fact is implied by its definition. (That's really just a nit though!)

@obulat obulat merged commit b33c91d into main Mar 28, 2023
@obulat obulat deleted the defer/tags_list branch March 28, 2023 05:14
dhruvkb pushed a commit that referenced this pull request Apr 14, 2023
Bumps [pytest-socket](https://github.com/miketheman/pytest-socket) from 0.5.1 to 0.6.0.
- [Release notes](https://github.com/miketheman/pytest-socket/releases)
- [Changelog](https://github.com/miketheman/pytest-socket/blob/main/CHANGELOG.md)
- [Commits](miketheman/pytest-socket@0.5.1...0.6.0)

---
updated-dependencies:
- dependency-name: pytest-socket
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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: internal improvement Improvement that benefits maintainers, not users 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: api Related to the Django API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants