Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebasing #330 #345

Merged
merged 1 commit into from
Jan 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pylint_django/tests/input/external_tastypie_noerror_foreign_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
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.
"""
from tastypie import fields
from tastypie.fields import ForeignKey

# pylint: disable=missing-docstring
from tastypie.resources import ModelResource


class MyTestResource(ModelResource): # pylint: disable=too-few-public-methods
field1 = ForeignKey("myapp.api.resource", "xxx")
field2 = fields.ForeignKey("myapp.api.resource", "xxx")
5 changes: 5 additions & 0 deletions pylint_django/transforms/foreignkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def is_foreignkey_in_class(node):
if not isinstance(node.parent.parent, ClassDef):
return False

# Make sure the outfit class is the subclass of django.db.models.Model
is_in_django_model_class = node_is_subclass(node.parent.parent, "django.db.models.base.Model", ".Model")
if not is_in_django_model_class:
return False

if isinstance(node.func, Attribute):
attr = node.func.attrname
elif isinstance(node.func, nodes.Name):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
extras_require={
"with_django": ["Django"],
"for_tests": ["django_tables2", "factory-boy", "coverage", "pytest", "wheel"],
"for_tests": ["django_tables2", "factory-boy", "coverage", "pytest", "wheel", "django-tastypie"],
},
license="GPLv2",
classifiers=[
Expand Down