-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the ForeiginKey detection more accurate
To handle this case: the project use tastypie and django. tastypie has a `ForeignKey` field which has the same name as django's `ForeignKey`. The issue is the lint trys resolving the `ForeignKey` for the tastypie `ForeignKey` which cause import error. In this commit, add a check to ensure the current class of the `ForeignKey` is a subclass of `Model` of django. Tested manually Test case added: func_noerror_foreign_key_in_non_django_class
- Loading branch information
Tommy Wu
committed
Nov 9, 2021
1 parent
f4f609e
commit 492454d
Showing
3 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
pylint_django/tests/input/external_tastypie_noerror_foreign_key.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
Checks that Pylint doesn't raise an error when a 'ForeignKey' appears in a | ||
non-django class | ||
The real case is described as follow: | ||
The project use tastypie and django. | ||
tastypie has a `ForeignKey` field which has the same name | ||
as django's `ForeignKey`. | ||
The issue is the lint trys resolving the `ForeignKey` for the | ||
tastypie `ForeignKey` which cause import error. | ||
""" | ||
# pylint: disable=missing-docstring | ||
from tastypie.resources import ModelResource | ||
from tastypie import fields | ||
from tastypie.fields import ForeignKey | ||
|
||
|
||
class MyTestResource(ModelResource): # pylint: disable=too-few-public-methods | ||
field1 = ForeignKey('myapp.api.resource', 'xxx') | ||
field2 = fields.ForeignKey('myapp.api.resource', 'xxx') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters