Skip to content

Commit

Permalink
Add exception handling for model field checking
Browse files Browse the repository at this point in the history
  • Loading branch information
yalef committed May 24, 2023
1 parent a317220 commit dbad132
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion flake8_django/checkers/model_content_order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import astroid
from astroid.exceptions import InferenceError
from functools import partial

from .base_model_checker import BaseModelChecker
Expand Down Expand Up @@ -33,7 +34,7 @@ def is_field_declaration(node):
):
return True
return False
except AttributeError:
except (AttributeError, InferenceError):
return False


Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/model_content_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,27 @@ def my_method(self):
@property
def random_property(self):
return '%s' % self


class CustomManager(models.Manager):
def manager_only_method(self):
return


class CustomQuerySet(models.QuerySet):
def manager_and_queryset_method(self):
return


class ModelWithCustomManager(models.Model):
"""
Model with custom manager which can't be inferred correctly.
"""
first_name = models.CharField(max_length=32)
objects = CustomManager.from_queryset(CustomQuerySet)()
class Meta:
verbose_name = 'test'
verbose_name_plural = 'tests'

def __str__(self):
return 'Perfectly fine!'

0 comments on commit dbad132

Please sign in to comment.