Why is the Django server running even when pytlinter shows that there's some bug in the code?

36 views
Skip to first unread message

Aaryan Dewan

unread,
Dec 3, 2019, 7:34:56 AM12/3/19
to Django users
I was just following this tutorial, on how to make Django apps and how to display a database to the user. I created a simple database in models.py and then, I defined a function in views.py, which used Item.objects.all(). Now Pylinter says that 'Item' has no 'objects' member!

So this should prevent the server from running ( as its a bug after all!), but if I type in python manage.py runserver, the terminal shows no error and the server starts functioning. 

Please see the photo attachment to get a clearer view of the problem!
bug1.png

Daniel Hepper

unread,
Dec 3, 2019, 8:27:35 AM12/3/19
to django...@googlegroups.com
Python is a dynamic programming language with a dynamic type system (as opposed to a static type system like for example Java), see https://en.wikipedia.org/wiki/Dynamic_programming_language

Among other things, that means that type checks are done during runtime.

That means, if Item really does not have an 'objects' member (i.e. Item is not a Django model), this will only lead to an error if this line of code is executed, i.e. you visit the URL that points to the index view function.

But if Item is a Django model, this is most likely a false positive of pylint. The Django ORM makes extensive use of the dynamic nature of Python, which can confuse pylint. There is a plugin for pylint to make it work more reliably with Django code: https://pypi.org/project/pylint-django/

Hope that helps,
Daniel


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6428642e-3d7d-4d95-b387-0894c8410897%40googlegroups.com.

Bruckner de Villiers

unread,
Dec 3, 2019, 8:30:18 AM12/3/19
to django...@googlegroups.com

I had the same issue and after trying various weird solutions on Stackoverflow, none of which worked, I found this simple solution – add this comment code to each line giving the error and it magically disappears:

 

# pylint: disable=no-member

 

 

Bruckner de Villiers

083 625 1086

--

Aaryan Dewan

unread,
Dec 3, 2019, 9:51:02 AM12/3/19
to Django users
Thanks for the reply! It was very helpful. 

"Class 'Item' has no 'objects' member" -- Could you explain what exactly a member is? 
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Aaryan Dewan

unread,
Dec 3, 2019, 9:51:23 AM12/3/19
to Django users
Thanks! :)


On Tuesday, December 3, 2019 at 7:00:18 PM UTC+5:30, Bruckner de Villiers wrote:

I had the same issue and after trying various weird solutions on Stackoverflow, none of which worked, I found this simple solution – add this comment code to each line giving the error and it magically disappears:

 

# pylint: disable=no-member

 

 

Bruckner de Villiers

083 625 1086

 

From: <django...@googlegroups.com> on behalf of Aaryan Dewan <dewan...@gmail.com>
Reply to: <django...@googlegroups.com>
Date: Tuesday, 03 December 2019 at 14:34
To: Django users <django...@googlegroups.com>
Subject: Why is the Django server running even when pytlinter shows that there's some bug in the code?

 

I was just following this tutorial, on how to make Django apps and how to display a database to the user. I created a simple database in models.py and then, I defined a function in views.py, which used Item.objects.all(). Now Pylinter says that 'Item' has no 'objects' member!

So this should prevent the server from running ( as its a bug after all!), but if I type in python manage.py runserver, the terminal shows no error and the server starts functioning. 

 

Please see the photo attachment to get a clearer view of the problem!

--
You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Bruckner de Villiers

unread,
Dec 4, 2019, 3:23:33 AM12/4/19
to django...@googlegroups.com

Which tutorial are you following?  Is it any good?

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/29ca61e2-640f-4e9e-8264-0bb691d0729c%40googlegroups.com.

Miracle

unread,
Dec 5, 2019, 6:01:41 PM12/5/19
to django...@googlegroups.com
Just like Daniel Hepper said,

pylint-django solves most of the linting problems you will encounter with django.

Install it and you're good to go.

Reply all
Reply to author
Forward
0 new messages