Skip to content

Commit 3181156

Browse files
committed
Suppress no-member errors for RelatedManager fields
seen in a real project where we have `product.build.first()` where Build.product is a FK to Product with related_name=build all of which causes factory to build a RelatedManager on the fly. For some reason I can't reproduce with the existing test but when I make this change it resolves the problem in the original code base that I was inspecting.
1 parent bacd7c3 commit 3181156

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pylint_django/augmentations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ def is_manager_attribute(node):
507507
"""Checks that node is attribute of Manager or QuerySet class."""
508508
parents = ('django.db.models.manager.Manager',
509509
'.Manager',
510+
'factory.base.BaseFactory.build',
510511
'django.db.models.query.QuerySet',
511512
'.QuerySet')
512513
return _attribute_is_magic(node, MANAGER_ATTRS.union(QS_ATTRS), parents)

pylint_django/tests/input/external_factory_boy_noerror.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Author(models.Model):
1515

1616
class Book(models.Model):
1717
title = models.CharField()
18-
author = models.ForeignKey(Author, on_delete=models.CASCADE)
18+
author = models.ForeignKey(Author, related_name='books', on_delete=models.CASCADE)
1919

2020

2121
class AuthorFactory(factory.django.DjangoModelFactory):
@@ -40,6 +40,9 @@ class BookTestCase(test.LiveServerTestCase):
4040
def _fixture_setup(self):
4141
super(BookTestCase, self)._fixture_setup()
4242
self.book = BookFactory()
43+
_author = AuthorFactory()
44+
_first_book = _author.books.first()
45+
self.assertIsNotNone(_first_book)
4346

4447
def test_author_is_not_none(self):
4548
self.assertGreater(self.book.pk, 0)

0 commit comments

Comments
 (0)