Pylance-release: Django model field

Created on 7 Aug 2020  路  5Comments  路  Source: microsoft/pylance-release

Hi, I am using django and I here is a bug I encountered, the method django.contrib.auth.authenticate returns and instance of django.contrib.auth.models.AbstarctBaseUser.

If I check for user.is_active pylance claims Cannot access member "is_active" for type "AbstractBaseUser" even though it is a defined field on the AbstractBaseUser class as shown in the screenshot.

Screenshot from 2020-08-07 14-34-08

  • Language Server version: pylance (v2020.8.0)
  • OS and version: Ubuntu 20.04 64bit
  • Python version: python 3.8.2 (pyenv, venv)
bug fixed in next version in backlog needs stub

Most helpful comment

Thanks again! I'm happy I was able to help out with this!

All 5 comments

You seem to be running Pylance at a type checking level above off. Once type checking is enabled, the stubs are important. In this case, the django stub we include (https://github.com/TypedDjango/django-stubs) does not say AbstractBaseUser has an is_active member, and we use the stubs for type checking (not the given code).

I have opened a Pull request in the Django Stubs Repo with a fix for this issue, and it was merged.

This issue can be closed when the Pylance extension will reflect these commits.

Thanks for that; I'll get your fix pulled in for tomorrow's release.

This issue has been fixed in version 2020.11.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020110-4-november-2020

Thanks again! I'm happy I was able to help out with this!

Was this page helpful?
0 / 5 - 0 ratings