Skip to content

DJ012 produces false positive when there are other dunder methods in model class #13892

@maddrum

Description

@maddrum

ruff check produces false positive DJ012 for Django models like so:

class Person(models.Model):
    name = models.CharField(xxxx)    
    
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        <some custom code>

    def save(*args, **kwargs):
        super().save(*args, `**kwargs)

According to Python best practices, dunder methods should always be kept at the beginning of the class.
But since save() is a Django method which is after other methods method it invokes error.

DJ012 should obey other Python class structuring, before evaluating Django styleguide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingBreaking API changehelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions