summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-11-28 20:04:21 +0100
committerGitHub <noreply@github.com>2023-11-28 20:04:21 +0100
commita4931cd75a1780923b02e43475ba5447df3adb31 (patch)
treedf3412eb589599430990d1efa010dd999884ff68 /django
parent5f9e5c1b0d5680f793ba7646d52ffab9e2c3623f (diff)
Refs #34380 -- Added FORMS_URLFIELD_ASSUME_HTTPS transitional setting.
This allows early adoption of the new default "https".
Diffstat (limited to 'django')
-rw-r--r--django/conf/__init__.py17
-rw-r--r--django/conf/global_settings.py5
-rw-r--r--django/forms/fields.py22
3 files changed, 36 insertions, 8 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 6b5f044e34..5568d7cc83 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -16,12 +16,18 @@ from pathlib import Path
import django
from django.conf import global_settings
from django.core.exceptions import ImproperlyConfigured
+from django.utils.deprecation import RemovedInDjango60Warning
from django.utils.functional import LazyObject, empty
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
DEFAULT_STORAGE_ALIAS = "default"
STATICFILES_STORAGE_ALIAS = "staticfiles"
+# RemovedInDjango60Warning.
+FORMS_URLFIELD_ASSUME_HTTPS_DEPRECATED_MSG = (
+ "The FORMS_URLFIELD_ASSUME_HTTPS transitional setting is deprecated."
+)
+
class SettingsReference(str):
"""
@@ -180,6 +186,12 @@ class Settings:
setattr(self, setting, setting_value)
self._explicit_settings.add(setting)
+ if self.is_overridden("FORMS_URLFIELD_ASSUME_HTTPS"):
+ warnings.warn(
+ FORMS_URLFIELD_ASSUME_HTTPS_DEPRECATED_MSG,
+ RemovedInDjango60Warning,
+ )
+
if hasattr(time, "tzset") and self.TIME_ZONE:
# When we can, attempt to validate the timezone. If we can't find
# this file, no check happens and it's harmless.
@@ -224,6 +236,11 @@ class UserSettingsHolder:
def __setattr__(self, name, value):
self._deleted.discard(name)
+ if name == "FORMS_URLFIELD_ASSUME_HTTPS":
+ warnings.warn(
+ FORMS_URLFIELD_ASSUME_HTTPS_DEPRECATED_MSG,
+ RemovedInDjango60Warning,
+ )
super().__setattr__(name, value)
def __delattr__(self, name):
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 6b91c6a716..8e1d2ace09 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -216,6 +216,11 @@ TEMPLATES = []
# Default form rendering class.
FORM_RENDERER = "django.forms.renderers.DjangoTemplates"
+# RemovedInDjango60Warning: It's a transitional setting helpful in early
+# adoption of "https" as the new default value of forms.URLField.assume_scheme.
+# Set to True to assume "https" during the Django 5.x release cycle.
+FORMS_URLFIELD_ASSUME_HTTPS = False
+
# Default email address to use for various automated correspondence from
# the site managers.
DEFAULT_FROM_EMAIL = "webmaster@localhost"
diff --git a/django/forms/fields.py b/django/forms/fields.py
index d1ba8af654..62d68985c0 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -15,6 +15,7 @@ from decimal import Decimal, DecimalException
from io import BytesIO
from urllib.parse import urlsplit, urlunsplit
+from django.conf import settings
from django.core import validators
from django.core.exceptions import ValidationError
from django.forms.boundfield import BoundField
@@ -762,14 +763,19 @@ class URLField(CharField):
def __init__(self, *, assume_scheme=None, **kwargs):
if assume_scheme is None:
- warnings.warn(
- "The default scheme will be changed from 'http' to 'https' in Django "
- "6.0. Pass the forms.URLField.assume_scheme argument to silence this "
- "warning.",
- RemovedInDjango60Warning,
- stacklevel=2,
- )
- assume_scheme = "http"
+ if settings.FORMS_URLFIELD_ASSUME_HTTPS:
+ assume_scheme = "https"
+ else:
+ warnings.warn(
+ "The default scheme will be changed from 'http' to 'https' in "
+ "Django 6.0. Pass the forms.URLField.assume_scheme argument to "
+ "silence this warning, or set the FORMS_URLFIELD_ASSUME_HTTPS "
+ "transitional setting to True to opt into using 'https' as the new "
+ "default scheme.",
+ RemovedInDjango60Warning,
+ stacklevel=2,
+ )
+ assume_scheme = "http"
# RemovedInDjango60Warning: When the deprecation ends, replace with:
# self.assume_scheme = assume_scheme or "https"
self.assume_scheme = assume_scheme