flake8-django icon indicating copy to clipboard operation
flake8-django copied to clipboard

Violations missed in sub-classes of abstract class

Open mschoettle opened this issue 3 years ago • 1 comments

I just started using flake8-django to evaluate it. Thanks for this great project!

I have the following models:

class AbstractModel(models.Model):
    class Meta:
        abstract = True

    name = models.CharField(_('Name'), max_length=100) [DJ12]
    code = models.CharField(_('Code'), max_length=10, unique=True) [DJ12]

    def __str__(self) -> str:
        return self.name


class A(AbstractModel):
    class Meta:
        ordering = ['name']

    some_url = models.URLField('Some URL')

Since there are no line numbers I added the violations at the end of the lines.

Expected Result:

class A should also have DJ12 as well as DJ10 and DJ11. If the super class is changed to models.Model these appear.

Also, if the definition for __str__ in AbstractModel is removed, there is no violation DJ08 reported for A.

A side comment/question: Instead of showing the violation for the wrong placement of Meta on each field, would it be possible to place the violation on Meta instead?

mschoettle avatar Jan 25 '22 23:01 mschoettle

Relates to #85 which is a generic issue for this issue.

I briefly played around with this and it seems to me that the only way to detect this properly is to track the class hierarchy to traverse the bases in order to consistently determine whether a class is a model or not. @rocioar is this correct or is there any other way to do this?

mschoettle avatar Oct 24 '22 12:10 mschoettle