Removed unneeded field_name checks within MigrationAutodetector.check_dependency(). by sarahboyce · Pull Request #19598 · django/django · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Removed unneeded field_name checks within MigrationAutodetector.check_dependency(). #19598

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sarahboyce
Copy link
Contributor

@sarahboyce sarahboyce commented Jun 27, 2025

While testing #19361, I was checking whether the elif check could be simplified to check test coverage and make sure we don't add anything unnecessary.

There are some OperationDependency.Type which are used for changes to both models and fields (such as OperationDependency.Type.CREATE) and some that are currently only used for changes to fields (such as OperationDependency.Type.REMOVE_ORDER_WRT).

I want to confirm if always checking whether the field name is or isn't None is something we want by design or whether a small refactor is worthwhile.
This might be just a personal preference decision but thought I would ask 👍

@github-actions github-actions bot added the no ticket Based on PR title, no linked Trac ticket label Jun 27, 2025
@@ -1235,6 +1235,22 @@ def test_trim_apps(self):
self.assertEqual(changes["otherapp"][0].name, "0001_initial")
self.assertNotIn("thirdapp", changes)

def test_check_dependency_invalid(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added to cover the ValueError but this is probably overkill and I'm happy to remove

Copy link
Member

@charettes charettes left a comment

Choose a reason for hiding this comment

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

I think that making the adjustments here makes sense as they as unnecessary but I think there might be value in digging a bit more here.

Since Python doesn't have support for parameterized enums this makes me wonder if we're using the wrong abstraction here and we should rely on classes instead that implement a check method

e.g.

class OperationDependency:
    def __init__(self, model_name):
        self.model_name

    @cached_property
    def model_name_lower(self):
        return self.model_name.lower()

    def check(self, operation):
        return False

class CreateModelDependency(OperationDependency):
    def check(self, operation):
        return (
             isinstance(operation, operations.CreateModel)
             and operation.name_lower == self.model_name_lower
         )

...

We could then simplify check_dependency to return dependency.check(operation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no ticket Based on PR title, no linked Trac ticket
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.