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] 500 error by enforcing valid UUID patterns in admin URLs #682 #978

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Unnati-Gupta24
Copy link

@Unnati-Gupta24 Unnati-Gupta24 commented Feb 12, 2025

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #682 .

Description of Changes

This PR fixes a 500 Internal Server Error caused by an incorrect NoReverseMatch when certain admin URLs are accessed. The issue happened because the URL pattern was too loose, allowing invalid UUID formats.

What’s changed?

  • Updated the regex to allow only valid UUIDs.
  • Added a check in admin.py to ensure UUIDs follow the correct format.
  • Updated url.py accordingly.
  • Kept support for both standard UUIDs (4290a79a-e740-4abf-b49e-9d5789b580f6) and hex format (4290a79ae7404abfb49e9d5789b580f6).
  • Maintained backward compatibility by keeping re_path where needed.

@devkapilbansal
Copy link
Member

Hi @Unnati-Gupta24
Can you pleaae add a test case for the change also?

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.

Django has a built-in uuid path converter:
https://docs.djangoproject.com/en/5.1/topics/http/urls/#path-converters

There's no automated test in this PR. Please add a test which fails without the changes, effectively replicating the bug. This test will protect us from the chance that this bug may be reintroduced inadvertently again in the future by other contributors.

@Unnati-Gupta24
Copy link
Author

Ok thanks understood...
Writing test cases for this

@Unnati-Gupta24
Copy link
Author

Unnati-Gupta24 commented Feb 27, 2025

I added a test case in admin.py, but the build is failing. I'm checking what might be causing this error.
There was an ELOF error in openwisp_controller/config/tests/utils.py, but it has been fixed.
Reformatted the files using openwisp-qa-format.
But the building is currently failing. I'm working on that..

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 this pull request may close these issues.

[bug] 500 internal server error for NoReverse match
3 participants