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

DJ012: False positive when declaring multiple managers #139

Open
YPCrumble opened this issue Dec 20, 2023 · 0 comments
Open

DJ012: False positive when declaring multiple managers #139

YPCrumble opened this issue Dec 20, 2023 · 0 comments

Comments

@YPCrumble
Copy link

Thank you for maintaining this library! I think I have found a bug in DJ12. Let's say I'm declaring multiple managers like in the docs:

# First, define the Manager subclass.
class DahlBookManager(models.Manager):
    def get_queryset(self):
        return super().get_queryset().filter(author="Roald Dahl")


# Then hook it into the Book model explicitly.
class Book(models.Model):
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=50)

    objects = models.Manager()  # The default manager.
    dahl_objects = DahlBookManager()  # The Dahl-specific manager.

flake8-django will flag dahl_objects, I believe because DJ12.is_manager_declaration assumes that managers are only named objects.

The issue I believe is that Django's docs state that the order of managers is important, i.e., the first manager defined is always the default manager: https://docs.djangoproject.com/en/5.0/topics/db/managers/#default-managers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant