#32991: Change in behavior of FileField.url between versions 2.2.16 -> 3.2.5;
returned 'relative' value contains leading slash
-------------------------------------+-------------------------------------
               Reporter:  ElchinM.   |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  File       |        Version:  3.2
  uploads/storage                    |
               Severity:  Normal     |       Keywords:  FileField.url
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Going through an upgrade of Django from version 2.2.16 to 3.2.5, believe I
 have found a regression in FileField.url

 I have searched all the release notes between these two versions for any
 mentions of "url" but didn't find changes being mentioned to this
 behavior. Some of the recent release notes for Django 2.2 (2.2.21 and
 2.2.23)  mention changes to FileField, maybe this is when the regression
 was introduced.

 Details of the issue:
 Using the same model FileField definition and settings in both versions.

 In 2.2.16 FileField.url returns a relative URL without a leading slash.
 In 3.2.5 the same call returns a relative URL with a leading slash.

 How to reproduce:

 Using the following Model definition:

 {{{
 from django.contrib.gis.db import models

 class TestModel(models.Model):
     file_field = models.FileField(
         upload_to='photos/%Y/%m/%d',
         max_length=255,
         null=True,
         help_text=u"Test"
     )
 }}}

 Using manage.py shell:
 In 2.2.16
 {{{
 >>> test_model = models.TestModel.objects.create()
 >>> f = open('setup.py')
 >>> from django.core.files.base import File
 >>> test_model.file_field.save('new_name', File(f))
 >>> test_model.file_field.url
 'photos/2021/08/05/new_name'
 >>> import django
 >>> django.__version__
 '2.2.16'
 }}}

 In 3.2.5:

 {{{
 >>> from vault import models
 >>> test_model = models.TestModel.objects.create()
 >>> f = open('setup.py')
 >>> from django.core.files.base import File
 >>> test_model.file_field.save('new_name', File(f))
 >>> test_model.file_field.url
 '/photos/2021/08/05/new_name'
 >>> import django
 >>> django.__version__
 '3.2.5'
 }}}

 The problem with the leading slash is that it is now treated as an
 absolute URL.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.ea9d363ea39ef53729f0a5c242c5bd6d%40djangoproject.com.

Reply via email to