-
Notifications
You must be signed in to change notification settings - Fork 117
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
Make the ForeiginKey detection more accurate #330
Make the ForeiginKey detection more accurate #330
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good but I think the class check can be made more robust by using the utils function which is also used in other places.
However we also need to update the test suite, see tests/input/func_noerror_foreignkeys.py
or another of the files with foreign
in the names (feel free to create another file if you want to).
You should be able to declare your model as per the original comment and together with the patch when the test suite executes it shouldn't report any errors.
186b47f
to
b5edc63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, I've added some comments.
Sadly I think Travis CI has exhausted to quota for this repository and will not execute the tests. Maybe it's time to switch to GitHub Actions.
pylint_django/tests/input/func_noerror_foreign_key_in_non_django_class.py
Outdated
Show resolved
Hide resolved
pylint_django/tests/input/func_noerror_foreign_key_in_non_django_class.py
Outdated
Show resolved
Hide resolved
b5edc63
to
5b98791
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change requested.
pylint_django/tests/input/func_noerror_foreign_key_in_non_django_class.py
Outdated
Show resolved
Hide resolved
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
5b98791
to
492454d
Compare
Hi Alexander @atodorov , could this commit be merged? |
@atodorov now that #336 (via #340) is merged, is this PR still good? After conflicts and changes are fixed that is - @qq915522927 if you have time to rebase given the recent changes that'd be great. |
I pulled the fork branch and fixed the conflicts and rebased in #345 . Tests all passed so I have merged it to master, and can close this PR now. |
we have a
api.py
which contains a tastypie resource, pylint regonized the resource'sForeiginKey
as django'sForeiginKey
by mistake, and then cause an error.In this commit, add a check to ensure the current class of the
ForeignKey
is a subclass ofModel
of django.Tested manually
Test case:
Before the fix, the new test case failed
After the fix, the test case passed: