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

(t) models.User.is_authenticated() will be deprecated in Django 2.0 #2664

Closed
FroggyFlox opened this issue Aug 21, 2023 · 1 comment · Fixed by #2665
Closed

(t) models.User.is_authenticated() will be deprecated in Django 2.0 #2664

FroggyFlox opened this issue Aug 21, 2023 · 1 comment · Fixed by #2665
Assignees

Comments

@FroggyFlox
Copy link
Member

When run using the Python warning flag (thanks @phillxnet!, #2655), we see the following warning:

/opt/rockstor/src/rockstor/storageadmin/views/home.py:68: RemovedInDjango20Warning: Using user.is_authenticated() and user.is_anonymous() as a method is deprecated. Remove the parentheses to use it as an attribute.
  if request.user.is_authenticated():

Steps to reproduce

As this is used in our home, the easiest way to trigger this warning is to "fully refresh" any webpage. For instance, go to system>users and press Ctrl + Shift + R.

Information

The warning itself is very clear and provides the solution. For background, we can have a look at the docs:
https://docs.djangoproject.com/en/1.11/ref/contrib/auth/#django.contrib.auth.models.User.is_authenticated

is_authenticated

Read-only attribute which is always True (as opposed to AnonymousUser.is_authenticated which is always False). This is a way to tell if the user has been authenticated. This does not imply any permissions and doesn’t check if the user is active or has a valid session. Even though normally you will check this attribute on request.user to find out whether it has been populated by the AuthenticationMiddleware (representing the currently logged-in user), you should know this attribute is True for any User instance.

Changed in Django 1.10:

In older versions, this was a method. Backwards-compatibility support for using it as a method will be removed in Django 2.0.

Our use

As per the log file, our only use of this now-attribute (was method) is in home.py:

buildvm155:/opt/rockstor # grep -r --include "*.py" "is_authenticated" src/rockstor/
src/rockstor/storageadmin/views/home.py:    if request.user.is_authenticated:
@FroggyFlox FroggyFlox self-assigned this Aug 21, 2023
FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Aug 21, 2023
Prior to Django 1.10, user.is_authenticated() was a method.
Since then, compatibility was ensured but this compatibility will be
removed in Django 2.0. This commit thus moves to using the
user.is_authenticated attribute instead.
@FroggyFlox FroggyFlox linked a pull request Aug 21, 2023 that will close this issue
phillxnet added a commit that referenced this issue Aug 22, 2023
…cated()-will-be-deprecated-in-Django-2.0

Use user.is_authenticated as an attribute #2664
@phillxnet
Copy link
Member

Closing as:
Fixed by #2665

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants