-
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
UnboundLocalError: local variable 'key_cls' referenced before assignment #232
Comments
Can you update to 2.0.9 and see if it reproduces. Also we'll need a code snippet which is triggering the error otherwise there's nothing we can do. |
@prokher from #229 (comment)
Please don't comment on closed issues, we are bound to miss them. Also post a reproducer. CC @imomaliev |
@federicobond Hi, could you provide a code snippet that fails? |
I could not reproduce this again, however, now I have another error with 2.0.9. I will open an issue soon. |
I can confirm that we still have the issue with 2.0.9, and already had it with 2.0.8.
|
@zout this traceback is useless without a code snippet to reproduce the problem. As you can see from our test suite we've added some code samples for the use-cases we could think of. When you see a failure for something that apparently works in CI you have to provide us with a reproducer. So far the entire discussion and "me too" comments here are useless because we don't have a reproducer and we can't do anything else to debug. If you want this fixed provide us with a code snippet that causes the crash. |
I've did some checking, and it seems that I have to import the model in the scope to make it work. When i run the exact same project with
there are no issues at all. So i've fixed it by importing all models into the scope of the file. UPDATE |
@atodorov I've narrowed it down to OneToOne relations. On my github there is a project that will trigger the error. Hope it helps in finding out the root cause: https://github.com/zout/django-pylint-issue |
The following simple file triggers the error for me: from django.db import models
class BadModel(models.Model):
bad = models.ForeignKey('Other', null=True, on_delete=models.CASCADE)
def foo(self):
return self.bad.name |
@snstanton where is 'Other' model defined ? |
It isn't defined anywhere. In my test case it's an unbound reference. This is the minimal test case I could come up with to cause the pylint crash. In my production code, it's just defined in another file in the same directory. I have a directory structure like:
All of the model files are included by the package |
I can confirm that rolling back to
does work around the issue. |
ok, I think I see where the problem is. When FK is specified as string we execute this branch:
and inside of it @imomaliev ^^^. Not sure how to handle this ATM. |
I will look into this in on next weekend. Currently on vacation. I think it could be solved by filtering out incoming args |
Any progress on this issue? |
@snstanton not yet. Been busy with work. If somebody is up for fixing this I could help reviewing PR afterwards. If not, I will hopefully have time this week |
Created PR with fix for |
@imomaliev looks like the issue is that other ForeignKey arguments are being evaluated as well. This line here: https://github.com/PyCQA/pylint-django/blob/c3edd260d94ca607d2c05a5cc33324921fae55e4/pylint_django/transforms/foreignkey.py#L78 is the one causing the whole problem, as in @snstanton case, the |
b/c this test file is only to validate we don't get the traceback seen in #232
b/c this test file is only to validate we don't get the traceback seen in #232
b/c this test file is only to validate we don't get the traceback seen in #232
The original traceback reported at the top has been fixed by @imomaliev in version 2.0.10 so closing this. For further discussion open new issues. |
I found this failure in my CI logs, but could not reproduce it locally. The corresponding code looks wrong but I don't know exactly how to correct it. If I can be of any help fixing it let me know.
Version: pylint-django==2.0.8
The text was updated successfully, but these errors were encountered: