[Django] #32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"

36 views
Skip to first unread message

Django

unread,
Dec 29, 2020, 3:09:03 PM12/29/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
----------------------------------------+------------------------
Reporter: Adam Hooper | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 3.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
Here's a piece of settings from a totally reasonable, sensible, okay
Docker integration-test environment

{{{
STATIC_URL = "http://minio/static/"
}}}

Django 3.1 will implicitly add "/" to the URL, so my URLs look like
""/http://minio/static/images/app-icons/favicon.ico".

The features and bugs that interact here:

* commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
STATIC_URL when STATIC_URL isn't a URL.
* bug #9202: according to Django, "http://minio/static/" isn't a valid
URL. (It is.)

Top me, the easiest fix is to address #9202....

--
Ticket URL: <https://code.djangoproject.com/ticket/32304>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 29, 2020, 3:10:48 PM12/29/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
------------------------------+--------------------------------------

Reporter: Adam Hooper | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by Adam Hooper:

Old description:

> Here's a piece of settings from a totally reasonable, sensible, okay
> Docker integration-test environment
>
> {{{
> STATIC_URL = "http://minio/static/"
> }}}
>
> Django 3.1 will implicitly add "/" to the URL, so my URLs look like
> ""/http://minio/static/images/app-icons/favicon.ico".
>
> The features and bugs that interact here:
>
> * commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
> STATIC_URL when STATIC_URL isn't a URL.
> * bug #9202: according to Django, "http://minio/static/" isn't a valid
> URL. (It is.)
>
> Top me, the easiest fix is to address #9202....

New description:

Here's a piece of settings from a totally reasonable, sensible, okay
Docker integration-test environment

{{{
STATIC_URL = "http://minio/static/"
}}}

Django 3.1 will implicitly add "/" to the URL, so my URLs look like
""/http://minio/static/images/app-icons/favicon.ico".

The features and bugs that interact here:

* commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
STATIC_URL when STATIC_URL isn't a URL.

* bug #9202 and #25418: according to Django, "http://minio/static/" isn't


a valid URL. (It is.)

Top me, the easiest fix is to address #9202 / #25418....

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:1>

Django

unread,
Dec 29, 2020, 3:11:59 PM12/29/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
------------------------------+--------------------------------------

Reporter: Adam Hooper | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by Adam Hooper:

Old description:

> Here's a piece of settings from a totally reasonable, sensible, okay


> Docker integration-test environment
>
> {{{
> STATIC_URL = "http://minio/static/"
> }}}
>
> Django 3.1 will implicitly add "/" to the URL, so my URLs look like
> ""/http://minio/static/images/app-icons/favicon.ico".
>
> The features and bugs that interact here:
>
> * commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
> STATIC_URL when STATIC_URL isn't a URL.

> * bug #9202 and #25418: according to Django, "http://minio/static/" isn't


> a valid URL. (It is.)
>

> Top me, the easiest fix is to address #9202 / #25418....

New description:

Here's a piece of settings from a totally reasonable, sensible, okay
Docker integration-test environment

{{{
STATIC_URL = "http://minio/static/"
}}}

Django 3.1 will implicitly add "/" to the URL, so my URLs look like
""/http://minio/static/images/app-icons/favicon.ico".

The features and bugs that interact here:

* commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
STATIC_URL when STATIC_URL isn't a URL.

* bug #9202 and #25418: according to Django, "http://minio/static/" isn't


a valid URL. (It is.)

Top me, the easiest fix is to address #9202 / #25418. Or to make
`STATIC_URL` use some logic that is different from URLValidator.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:2>

Django

unread,
Dec 29, 2020, 3:35:52 PM12/29/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
------------------------------+--------------------------------------

Reporter: Adam Hooper | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by Adam Hooper):

My workaround was to create a phony URL and point to it in
{{{/etc/hosts}}}.

Yes, really.
https://github.com/CJWorkbench/cjworkbench/commit/6aec10f441f5392bda7df247cddc8828b52a0c84

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:3>

Django

unread,
Dec 29, 2020, 3:36:24 PM12/29/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
------------------------------+--------------------------------------

Reporter: Adam Hooper | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 3.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by Adam Hooper:

Old description:

> Here's a piece of settings from a totally reasonable, sensible, okay


> Docker integration-test environment
>
> {{{
> STATIC_URL = "http://minio/static/"
> }}}
>
> Django 3.1 will implicitly add "/" to the URL, so my URLs look like
> ""/http://minio/static/images/app-icons/favicon.ico".
>
> The features and bugs that interact here:
>
> * commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
> STATIC_URL when STATIC_URL isn't a URL.

> * bug #9202 and #25418: according to Django, "http://minio/static/" isn't


> a valid URL. (It is.)
>

> Top me, the easiest fix is to address #9202 / #25418. Or to make
> `STATIC_URL` use some logic that is different from URLValidator.

New description:

Here's a piece of settings from a totally reasonable, sensible, okay
Docker integration-test environment

{{{
STATIC_URL = "http://minio/static/"
}}}

Django 3.1 will implicitly add "/" to the URL, so my URLs look like
{{{/http://minio/static/images/app-icons/favicon.ico}}}

The features and bugs that interact here:

* commit c574bec, adding feature #25598, prepends SCRIPT_NAME to
STATIC_URL when STATIC_URL isn't a URL.

* bug #9202 and #25418: according to Django, "http://minio/static/" isn't


a valid URL. (It is.)

Top me, the easiest fix is to address #9202 / #25418. Or to make


`STATIC_URL` use some logic that is different from URLValidator.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:4>

Django

unread,
Dec 30, 2020, 1:53:08 AM12/30/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
-------------------------------------+------------------------------------

Reporter: Adam Hooper | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* cc: Florian Apolloner (added)
* component: Core (Other) => contrib.staticfiles
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Thanks for the report, as a workaround you can set the
[https://docs.djangoproject.com/en/3.1/ref/settings/#force-script-name
FORCE_SCRIPT_NAME] setting to an empty string:
{{{#!python
FORCE_SCRIPT_NAME = ''
}}}

Ticket #9202 was rejected and will not be fixed. I think it should be fine
to add `http://` and `https://` to recognizing absolute paths, e.g.
{{{
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 23fee7d5b7..c2ddc942db 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -139,7 +139,7 @@ class LazySettings(LazyObject):
except (ValidationError, AttributeError):
pass
# Don't apply prefix to absolute paths.
- if value.startswith('/'):
+ if value.startswith(('http://', 'https://', '/')):
return value
from django.urls import get_script_prefix
return '%s%s' % (get_script_prefix(), value)
}}}

Florian, What do you think?

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:5>

Django

unread,
Dec 30, 2020, 4:20:28 AM12/30/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
-------------------------------------+------------------------------------

Reporter: Adam Hooper | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by Florian Apolloner):

Uff, yes that is certainly a bug. I think your proposed fix is okay; but
I'd also remove the usage of the `URLValidator` completely. Maybe:

{{{
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 23fee7d5b7..fc36b64d05 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -16,7 +16,6 @@ from pathlib import Path
import django
from django.conf import global_settings
from django.core.exceptions import ImproperlyConfigured, ValidationError
-from django.core.validators import URLValidator
from django.utils.deprecation import RemovedInDjango40Warning
from django.utils.functional import LazyObject, empty

@@ -132,14 +131,8 @@ class LazySettings(LazyObject):
Useful when the app is being served at a subpath and manually
prefixing
subpath to STATIC_URL and MEDIA_URL in settings is inconvenient.
"""
- # Don't apply prefix to valid URLs.
- try:
- URLValidator()(value)
- return value
- except (ValidationError, AttributeError):
- pass
- # Don't apply prefix to absolute paths.


- if value.startswith('/'):

+ # Don't apply prefix to absolute paths and URLs.
+ if value.startswith(('/', 'http://', 'https://')):


return value
from django.urls import get_script_prefix
return '%s%s' % (get_script_prefix(), value)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:6>

Django

unread,
Dec 30, 2020, 5:01:53 AM12/30/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
-------------------------------------+-------------------------------------
Reporter: Adam Hooper | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned

Component: contrib.staticfiles | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Mariusz Felisiak
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:7>

Django

unread,
Dec 30, 2020, 5:25:01 AM12/30/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
-------------------------------------+-------------------------------------
Reporter: Adam Hooper | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Hasan Ramezani):

Mariusz,

I didn't realize that you assigned the ticket to yourself. I just created
a [https://github.com/django/django/pull/13823 PR] based on Florian
Apolloner proposed patch.
Feel free to close my PR if you have something else in your mind.

Thanks

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:8>

Django

unread,
Dec 30, 2020, 5:26:36 AM12/30/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
-------------------------------------+-------------------------------------
Reporter: Adam Hooper | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/13824/ PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:9>

Django

unread,
Dec 30, 2020, 5:48:56 AM12/30/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
-------------------------------------+-------------------------------------
Reporter: Adam Hooper | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:10>

Django

unread,
Dec 31, 2020, 7:19:08 AM12/31/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
-------------------------------------+-------------------------------------
Reporter: Adam Hooper | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 3.1
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"e13b71403bd1568abed237858127677144d43d23" e13b7140]:
{{{
#!CommitTicketReference repository=""
revision="e13b71403bd1568abed237858127677144d43d23"
Fixed #32304 -- Fixed prefixing STATIC_URL and MEDIA_URL by SCRIPT_NAME
for absolute URLs with no domain.

Thanks Adam Hooper for the report.

Regression in c574bec0929cd2527268c96a492d25223a9fd576.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:11>

Django

unread,
Dec 31, 2020, 7:20:10 AM12/31/20
to django-...@googlegroups.com
#32304: Django adds spurious "/" prefix to settings.STATIC_URL="http://server/"
-------------------------------------+-------------------------------------
Reporter: Adam Hooper | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 3.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"5fdc81d8930b85849a39e550fa54be1cad10d74d" 5fdc81d]:
{{{
#!CommitTicketReference repository=""
revision="5fdc81d8930b85849a39e550fa54be1cad10d74d"
[3.1.x] Fixed #32304 -- Fixed prefixing STATIC_URL and MEDIA_URL by


SCRIPT_NAME for absolute URLs with no domain.

Thanks Adam Hooper for the report.

Regression in c574bec0929cd2527268c96a492d25223a9fd576.
Backport of e13b71403bd1568abed237858127677144d43d23 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32304#comment:12>

Reply all
Reply to author
Forward
0 new messages