Skip to content

Commit bacd7c3

Browse files
committed
Suppress no-member for LazyFunction in factories
the pattern I've seen is attr.pk where attr is a field from the model but inside the factory is calculated as a LazyFunction, usually pointing to a first/last of possible entries in the DB.
1 parent a880c07 commit bacd7c3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pylint_django/augmentations/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ def is_model_factory(node):
432432
except: # noqa: E722, pylint: disable=bare-except
433433
return False
434434

435-
parents = ('factory.declarations.SubFactory', 'factory.django.DjangoModelFactory')
435+
parents = ('factory.declarations.LazyFunction',
436+
'factory.declarations.SubFactory',
437+
'factory.django.DjangoModelFactory')
436438

437439
for parent_class in parent_classes:
438440
try:

pylint_django/tests/input/external_factory_boy_noerror.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Meta:
3131

3232
title = factory.Sequence(lambda n: 'Book %d' % n)
3333
author = factory.SubFactory(AuthorFactory)
34+
reviewer = factory.LazyFunction(Author.objects.first())
3435

3536

3637
class BookTestCase(test.LiveServerTestCase):
@@ -46,3 +47,6 @@ def test_author_is_not_none(self):
4647

4748
self.assertIsNotNone(self.book.title)
4849
self.assertIsNotNone(self.book.author.name)
50+
51+
def test_reviewer_is_not_none(self):
52+
self.assertGreater(self.book.reviewer.pk, 0)

0 commit comments

Comments
 (0)