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

[fix] Fixed - Exception raised on opening non existing user ID #228 #233

Merged

Conversation

Saurav-Shrivastav
Copy link
Contributor

  • Added a test to check the response status on navigating to a non-existing user change page
  • Handled exceptions for an invalid UUID and a non-existing user

Fixes #228

@coveralls
Copy link

coveralls commented Mar 10, 2021

Coverage Status

Coverage remained the same at 97.25% when pulling abfccb3 on Saurav-Shrivastav:issues/228-fix-exception-raised into fb787a1 on openwisp:master.

@pandafy pandafy self-requested a review March 10, 2021 15:35
Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work @Saurav-Shrivastav ! 👍

I have requested some minor changes, see my comments below.

openwisp_users/tests/test_admin.py Outdated Show resolved Hide resolved
openwisp_users/tests/test_admin.py Outdated Show resolved Hide resolved
@Saurav-Shrivastav
Copy link
Contributor Author

Thanks for the suggestions @pandafy. I've implemented them.

Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Saurav-Shrivastav I manually tested the code today found a discrepancy. While you have achieved what was described in the issue description, that breaks the normal flow of Django Admin.

The change_view method of django.contrib.admin.ModelAdmin is implemented in a way that if an object does not exists or if validation fails, the user is redirected to the admin index page.

See following screenshots which I took while testing similar behaviour with change_view of organization model.

image
image

With the current patch, the user will be greeted with a 404 Not Found page if the corresponding object of User model does not exists or fails Validation.

I have shared suggestions to improve the current patch so it follows typical flow of Django Admin.

openwisp_users/admin.py Outdated Show resolved Hide resolved
openwisp_users/tests/test_admin.py Outdated Show resolved Hide resolved
@Saurav-Shrivastav Saurav-Shrivastav force-pushed the issues/228-fix-exception-raised branch 2 times, most recently from 9b83c43 to a215ab5 Compare March 13, 2021 07:54
@Saurav-Shrivastav Saurav-Shrivastav marked this pull request as draft March 13, 2021 09:15
openwisp_users/admin.py Outdated Show resolved Hide resolved
@Saurav-Shrivastav Saurav-Shrivastav marked this pull request as ready for review March 16, 2021 04:02
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to everyone involved! I spotted one aspect which can be improved.

openwisp_users/admin.py Outdated Show resolved Hide resolved
# check for version < 3.1
content = f'User with ID "{id}" doesn\'t exist. Perhaps it was deleted?'
else:
content = f'User with ID “{id}” doesn’t exist. Perhaps it was deleted?'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have avoided the version switch and checked only for part of the string, however, since it's already done and the check works, we can leave it, thanks.

Copy link
Contributor Author

@Saurav-Shrivastav Saurav-Shrivastav Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like this?

content = '<li class="warning">User with ID '

I did think about this, but then this might lead to us missing out on checking the keywords like WRONG or the invalid-id.

content = f'User with ID "{id}" doesn\'t exist. Perhaps it was deleted?'
else:
content = f'User with ID “{id}” doesn’t exist. Perhaps it was deleted?'
response.content = html.unescape(response.content.decode())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to do this here. You can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to line no 202?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required for Django 2.2, since it converts HTML entities like &quot; to "

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Saurav-Shrivastav, but support for django 2.2 was already planned to be dropped, the PR was ready but not merged yet, now is merged: #199.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Saurav-Shrivastav, but support for django 2.2 was already planned to be dropped, the PR was ready but not merged yet, now is merged: #199.

…sp#228

- Added a test to check the response status on navigating to a non-existing user change page
- Handled exceptions for an invalid UUID and a non-existing user

Fixes openwisp#228
@Saurav-Shrivastav
Copy link
Contributor Author

@nemesisdesign I have removed the portion of code that checked the django version, looks good now ^^

@nemesifier nemesifier merged commit 114b16b into openwisp:master Mar 20, 2021
@nemesifier
Copy link
Member

Thanks @Saurav-Shrivastav 👍

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

Successfully merging this pull request may close these issues.

[bug] Regression: opening non existing user ID raises an exception
5 participants