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

Remove unnecessary write-time validating URLTextField #4322

Merged
merged 1 commit into from
May 15, 2024

Conversation

sarayourfriend
Copy link
Contributor

@sarayourfriend sarayourfriend commented May 14, 2024

Fixes

Fixes #4320 by @AetherUnbound

Description

As discussed in the PR linked by the issue and the issue itself, the URLTextField is wholly unnecessary. The usage of URLField on these model fields was already superfluous: the only feature URLField adds over CharField is write-time validation to check that strings "look like" URLs. However, the fields are literally never written to using Django ORM in application code, the data refresh process writes directly to the database in raw SQL inserts and never refers to Django's models at all.

In the related PR, we added URLTextField to maintain the consistency with the original implementation. But really we can just remove it. There's no reason to keep this around. All code is a liability, and if we can remove it (if it is unused) we should. In this case, removing it is so trivial and of literally zero consequence for the application because the extra code and routines URL[Text]Field added were dead code. There is no reason not to remove it, and it is in fact prudent to do so.

Testing Instructions

CI should pass. There are no new migrations. Changing URLTextField to TextField does not result in any changes to the SQL content of that migration. You can test this out by checking out main and running just down -v && just api/up && just api/init, then check out this branch and run just logs web and confirm that there is no issue with migrations. Additionally, make a request to the images and audio endpoints which will likewise confirm there is no meaningful change to the way the application reads these fields. Compare below to the SQL in the original PR (#4315):

BEGIN;
--
-- Alter field audio_set_foreign_identifier on audio
--
ALTER TABLE "audio" ALTER COLUMN "audio_set_foreign_identifier" TYPE text USING "audio_set_foreign_identifier"::text;
--
-- Alter field creator on audio
--
ALTER TABLE "audio" ALTER COLUMN "creator" TYPE text USING "creator"::text;
--
-- Alter field creator_url on audio
--
ALTER TABLE "audio" ALTER COLUMN "creator_url" TYPE text USING "creator_url"::text;
--
-- Alter field foreign_identifier on audio
--
DROP INDEX IF EXISTS "audio_foreign_identifier_617f66ad_like";
ALTER TABLE "audio" ALTER COLUMN "foreign_identifier" TYPE text USING "foreign_identifier"::text;
--
-- Alter field foreign_landing_url on audio
--
ALTER TABLE "audio" ALTER COLUMN "foreign_landing_url" TYPE text USING "foreign_landing_url"::text;
--
-- Alter field thumbnail on audio
--
ALTER TABLE "audio" ALTER COLUMN "thumbnail" TYPE text USING "thumbnail"::text;
--
-- Alter field title on audio
--
ALTER TABLE "audio" ALTER COLUMN "title" TYPE text USING "title"::text;
--
-- Alter field url on audio
--
DROP INDEX IF EXISTS "audio_url_b6a832d3_like";
ALTER TABLE "audio" ALTER COLUMN "url" TYPE text USING "url"::text;
--
-- Alter field creator on audioset
--
ALTER TABLE "audioset" ALTER COLUMN "creator" TYPE text USING "creator"::text;
--
-- Alter field creator_url on audioset
--
ALTER TABLE "audioset" ALTER COLUMN "creator_url" TYPE text USING "creator_url"::text;
--
-- Alter field foreign_identifier on audioset
--
DROP INDEX IF EXISTS "audioset_foreign_identifier_ef0c8e77_like";
ALTER TABLE "audioset" ALTER COLUMN "foreign_identifier" TYPE text USING "foreign_identifier"::text;
--
-- Alter field foreign_landing_url on audioset
--
ALTER TABLE "audioset" ALTER COLUMN "foreign_landing_url" TYPE text USING "foreign_landing_url"::text;
--
-- Alter field thumbnail on audioset
--
ALTER TABLE "audioset" ALTER COLUMN "thumbnail" TYPE text USING "thumbnail"::text;
--
-- Alter field title on audioset
--
ALTER TABLE "audioset" ALTER COLUMN "title" TYPE text USING "title"::text;
--
-- Alter field url on audioset
--
DROP INDEX IF EXISTS "audioset_url_144aed53_like";
ALTER TABLE "audioset" ALTER COLUMN "url" TYPE text USING "url"::text;
--
-- Alter field creator on image
--
ALTER TABLE "image" ALTER COLUMN "creator" TYPE text USING "creator"::text;
--
-- Alter field creator_url on image
--
ALTER TABLE "image" ALTER COLUMN "creator_url" TYPE text USING "creator_url"::text;
--
-- Alter field foreign_identifier on image
--
DROP INDEX IF EXISTS "image_foreign_identifier_4c72d3ee_like";
ALTER TABLE "image" ALTER COLUMN "foreign_identifier" TYPE text USING "foreign_identifier"::text;
--
-- Alter field foreign_landing_url on image
--
ALTER TABLE "image" ALTER COLUMN "foreign_landing_url" TYPE text USING "foreign_landing_url"::text;
--
-- Alter field thumbnail on image
--
ALTER TABLE "image" ALTER COLUMN "thumbnail" TYPE text USING "thumbnail"::text;
--
-- Alter field title on image
--
ALTER TABLE "image" ALTER COLUMN "title" TYPE text USING "title"::text;
--
-- Alter field url on image
--
DROP INDEX IF EXISTS "image_url_c6aabda2_like";
ALTER TABLE "image" ALTER COLUMN "url" TYPE text USING "url"::text;
COMMIT;

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.
  • [N/A] 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.
  • [N/A] I ran the DAG documentation generator (just catalog/generate-docs for catalog
    PRs) 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
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.

@sarayourfriend sarayourfriend added 🟧 priority: high Stalls work on the project or its dependents 💻 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 May 14, 2024
@sarayourfriend sarayourfriend requested a review from a team as a code owner May 14, 2024 08:09
Copy link

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

@github-actions github-actions bot added the migrations Modifications to Django migrations label May 14, 2024
Copy link
Member

@krysal krysal left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

LGTM

@sarayourfriend sarayourfriend merged commit bb2bfd5 into main May 15, 2024
73 checks passed
@sarayourfriend sarayourfriend deleted the remove/unneeded-url-fields branch May 15, 2024 19:25
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 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
Development

Successfully merging this pull request may close these issues.

Remove bespoke URLTextField in favor of base TextField
3 participants