[PR #5978] [MERGED] Fix use of URLValidator to correctly validate RELEASE_CHECK_URL #13080

Closed
opened 2025-12-29 22:25:17 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/5978
Author: @jathanism
Created: 3/13/2021
Status: Merged
Merged: 3/17/2021
Merged by: @jeremystretch

Base: developHead: jathanism-fix-invalid-release_check_url


📝 Commits (1)

  • 68082a8 Fix use of URLValidator to correctly validate RELEASE_CHECK_URL

📊 Changes

1 file changed (+7 additions, -4 deletions)

View changed files

📝 netbox/netbox/settings.py (+7 -4)

📄 Description

Fixes: #5977

This is a minor patch that makes the test in netbox.settings to correctly validate that RELEASE_CHECK_URL is a valid URL. I wasn't able to find a place where these settings are tested in the test suite, so I am providing some interactive Python shell output to illustrate the fix:

In [1]: from django.core.validators import URLValidator

In [2]: from django.core.exceptions import ImproperlyConfigured, ValidationError

In [3]: RELEASE_CHECK_URL = 'bogus url'

In [4]: if RELEASE_CHECK_URL:
   ...:     validator = URLValidator(
   ...:         message=(
   ...:             "RELEASE_CHECK_URL must be a valid API URL. Example: "
   ...:             "https://api.github.com/repos/netbox-community/netbox"
   ...:         )
   ...:     )
   ...:     try:
   ...:         validator(RELEASE_CHECK_URL)
   ...:     except ValidationError as err:
   ...:         raise ImproperlyConfigured(str(err))
   ...:
---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
<ipython-input-4-8bf07c825907> in <module>
      8     try:
----> 9         validator(RELEASE_CHECK_URL)
     10     except ValidationError as err:

~/Library/Caches/pypoetry/virtualenvs/nautobot-b2ttWva6-py3.8/lib/python3.8/site-packages/django/core/validators.py in __call__(self, value)
    104         if scheme not in self.schemes:
--> 105             raise ValidationError(self.message, code=self.code)
    106

ValidationError: ['RELEASE_CHECK_URL must be a valid API URL. Example: https://api.github.com/repos/netbox-community/netbox']

During handling of the above exception, another exception occurred:

ImproperlyConfigured                      Traceback (most recent call last)
<ipython-input-4-8bf07c825907> in <module>
      9         validator(RELEASE_CHECK_URL)
     10     except ValidationError as err:
---> 11         raise ImproperlyConfigured(str(err))
     12

ImproperlyConfigured: ['RELEASE_CHECK_URL must be a valid API URL. Example: https://api.github.com/repos/netbox-community/netbox']

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/5978 **Author:** [@jathanism](https://github.com/jathanism) **Created:** 3/13/2021 **Status:** ✅ Merged **Merged:** 3/17/2021 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `jathanism-fix-invalid-release_check_url` --- ### 📝 Commits (1) - [`68082a8`](https://github.com/netbox-community/netbox/commit/68082a88a78534417541d8f69191e153094585dd) Fix use of `URLValidator` to correctly validate `RELEASE_CHECK_URL` ### 📊 Changes **1 file changed** (+7 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `netbox/netbox/settings.py` (+7 -4) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be opened for approval prior to filing a pull request. This helps avoid wasting time and effort on something that we might not be able to accept. Please indicate the relevant feature request or bug report below. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ACCEPTED BUG REPORT OR FEATURE REQUEST, IT WILL BE MARKED AS INVALID AND CLOSED. --> ### Fixes: #5977 <!-- Please include a summary of the proposed changes below. --> This is a minor patch that makes the test in `netbox.settings` to correctly validate that `RELEASE_CHECK_URL` is a valid URL. I wasn't able to find a place where these settings are tested in the test suite, so I am providing some interactive Python shell output to illustrate the fix: ``` In [1]: from django.core.validators import URLValidator In [2]: from django.core.exceptions import ImproperlyConfigured, ValidationError In [3]: RELEASE_CHECK_URL = 'bogus url' In [4]: if RELEASE_CHECK_URL: ...: validator = URLValidator( ...: message=( ...: "RELEASE_CHECK_URL must be a valid API URL. Example: " ...: "https://api.github.com/repos/netbox-community/netbox" ...: ) ...: ) ...: try: ...: validator(RELEASE_CHECK_URL) ...: except ValidationError as err: ...: raise ImproperlyConfigured(str(err)) ...: --------------------------------------------------------------------------- ValidationError Traceback (most recent call last) <ipython-input-4-8bf07c825907> in <module> 8 try: ----> 9 validator(RELEASE_CHECK_URL) 10 except ValidationError as err: ~/Library/Caches/pypoetry/virtualenvs/nautobot-b2ttWva6-py3.8/lib/python3.8/site-packages/django/core/validators.py in __call__(self, value) 104 if scheme not in self.schemes: --> 105 raise ValidationError(self.message, code=self.code) 106 ValidationError: ['RELEASE_CHECK_URL must be a valid API URL. Example: https://api.github.com/repos/netbox-community/netbox'] During handling of the above exception, another exception occurred: ImproperlyConfigured Traceback (most recent call last) <ipython-input-4-8bf07c825907> in <module> 9 validator(RELEASE_CHECK_URL) 10 except ValidationError as err: ---> 11 raise ImproperlyConfigured(str(err)) 12 ImproperlyConfigured: ['RELEASE_CHECK_URL must be a valid API URL. Example: https://api.github.com/repos/netbox-community/netbox'] ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:25:17 +01:00
adam closed this issue 2025-12-29 22:25:17 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13080