[Django] #28428: Add support for Pathlib objects in django.core.storage

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #28428: Add support for Pathlib objects in django.core.storage

Django
#28428: Add support for Pathlib objects in django.core.storage
-----------------------------------------+------------------------
               Reporter:  Tom            |          Owner:  nobody
                   Type:  New feature    |         Status:  new
              Component:  Uncategorized  |        Version:  master
               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              |
-----------------------------------------+------------------------
 Code in django.core.storage will explode when given a Pathlib object on
 Python 3.4 and 3.5. For example, this throws a cryptic `AttributeError:
 'PosixPath' object has no attribute 'rfind'` exception due to
 `generate_filename` only expecting strings:


 {{{
 def upload_to(filename):
       return pathlib.Path(filename)

 class Storage(models.Model):
    file = models.FileField(upload_to=upload_to)
 }}}


 More generally, it would be nice if all methods in the django.core.files
 accepted pathlib objects, and used pathlib objects internally. For
 compatibility reasons I think strings would have to be returned.

--
Ticket URL: <https://code.djangoproject.com/ticket/28428>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/046.81544b01bc8631b227f16fa3cd6bde57%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28428: Add support for Pathlib objects in django.core.storage

Django
#28428: Add support for Pathlib objects in django.core.storage
-------------------------------------+-------------------------------------
     Reporter:  Tom                  |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  File                 |                  Version:  master
  uploads/storage                    |
     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
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * component:  Uncategorized => File uploads/storage


Comment:

 Do you have a use case in mind? What are the advantages?

--
Ticket URL: <https://code.djangoproject.com/ticket/28428#comment:1>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.5d39ec781056f59b9b39fb8aac37b2ef%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28428: Add support for Pathlib objects in django.core.storage

Django
In reply to this post by Django
#28428: Add support for Pathlib objects in django.core.storage
-------------------------------------+-------------------------------------
     Reporter:  Tom                  |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  File                 |                  Version:  master
  uploads/storage                    |
     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 Tom):

 In my case we have a bunch of methods in our applications that all use
 pathlib instances, some of which is used by our upload_to methods. It
 feels a bit strange to have to return the string representation from them
 when interacting with Django. With Python 2 support out of the picture
 there isn't much reason to, other than historical ones.

 The main advantage is readability, in a lot of cases using Pathlib makes
 `os.path` heavy code a lot less dense.

--
Ticket URL: <https://code.djangoproject.com/ticket/28428#comment:2>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.7534f8214748dbb415078d4acc0b4f8a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28428: Add support for Pathlib objects in django.core.storage

Django
In reply to this post by Django
#28428: Add support for Pathlib objects in django.core.storage
-------------------------------------+-------------------------------------
     Reporter:  Tom                  |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  File                 |                  Version:  master
  uploads/storage                    |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * stage:  Unreviewed => Someday/Maybe


Comment:

 I'm not sure. I guess I'd have to see a patch to evaluate the idea.

--
Ticket URL: <https://code.djangoproject.com/ticket/28428#comment:3>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.f3e5eeac1279ae62a382ca1f8dedf027%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28428: Add support for Pathlib objects in django.core.storage

Django
In reply to this post by Django
#28428: Add support for Pathlib objects in django.core.storage
-------------------------------------+-------------------------------------
     Reporter:  Tom Forbes           |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  File                 |                  Version:  master
  uploads/storage                    |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Roger G. Coram):

 As of Python 3.6 (specifically running 3.6.3)
 `django.core.files.storage.Storage.generate_filename` doesn't appear to
 raise this error when passed a `pathlib.Path`. Instead the `os.path.split`
 therein appears to handle it as expected:

 {{{
 Python 3.6.3 (default, Oct  6 2017, 08:44:35)
 >>> import os, pathlib
 >>> os.path.split(pathlib.PosixPath("some/folder/test_with_space.txt"))
 ('some/folder', 'test_with_space.txt')
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28428#comment:4>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.548103dfcbca7262dc8efab8d43d9349%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28428: Add support for Pathlib objects in django.core.storage

Django
In reply to this post by Django
#28428: Add support for Pathlib objects in django.core.storage
-------------------------------------+-------------------------------------
     Reporter:  Tom Forbes           |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  File                 |                  Version:  master
  uploads/storage                    |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Someday/Maybe
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Kyle Agronick):

 Pathlib provides a much nicer object oriented syntax rather than dealing
 with strings. os.path supports pathlib. Django really should too. At the
 very least all you would have to do is cast to a string and everything
 else would work as normal.

--
Ticket URL: <https://code.djangoproject.com/ticket/28428#comment:5>
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.4810ce9459eadd0a11cb7f81828d4584%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28428: Add support for Pathlib objects in django.core.storage

Django
In reply to this post by Django
#28428: Add support for Pathlib objects in django.core.storage
--------------------------------------+------------------------------------
     Reporter:  Tom Forbes            |                    Owner:  nobody
         Type:  New feature           |                   Status:  new
    Component:  File uploads/storage  |                  Version:  master
     Severity:  Normal                |               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 Claude Paroz):

 * has_patch:  0 => 1
 * stage:  Someday/Maybe => Accepted


Comment:

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

 It's easier now that Python 3.6 is the minimal version.

--
Ticket URL: <https://code.djangoproject.com/ticket/28428#comment:6>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.91a39ec803472f35a93a472fa577b28d%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28428: Add support for Pathlib objects in django.core.storage

Django
In reply to this post by Django
#28428: Add support for Pathlib objects in django.core.storage
--------------------------------------+------------------------------------
     Reporter:  Tom Forbes            |                    Owner:  nobody
         Type:  New feature           |                   Status:  new
    Component:  File uploads/storage  |                  Version:  master
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    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:"d1c2e6dd04d4ddc8ace17e6abfed16ac46459d1e" d1c2e6dd]:
 {{{
 #!CommitTicketReference repository=""
 revision="d1c2e6dd04d4ddc8ace17e6abfed16ac46459d1e"
 Refs #28428 -- Made FileField.upload_to support pathlib.Path.
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28428#comment:8>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.54e8efb2c2375080a69f23a09b48f30b%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28428: Add support for Pathlib objects in django.core.storage

Django
In reply to this post by Django
#28428: Add support for Pathlib objects in django.core.storage
--------------------------------------+------------------------------------
     Reporter:  Tom Forbes            |                    Owner:  nobody
         Type:  New feature           |                   Status:  new
    Component:  File uploads/storage  |                  Version:  master
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    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:"af69842dbd98e69519f1263eca2619c3165ba13b" af69842d]:
 {{{
 #!CommitTicketReference repository=""
 revision="af69842dbd98e69519f1263eca2619c3165ba13b"
 Refs #28428 -- Added test for a callable FileField.upload_to that returns
 pathlib.Path.
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28428#comment:7>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.a7cd42304e85a5fde0dacfc6daae5198%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #28428: Add support for Pathlib objects in django.core.storage

Django
In reply to this post by Django
#28428: Add support for Pathlib objects in django.core.storage
--------------------------------------+------------------------------------
     Reporter:  Tom Forbes            |                    Owner:  nobody
         Type:  New feature           |                   Status:  new
    Component:  File uploads/storage  |                  Version:  master
     Severity:  Normal                |               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 felixxm):

 * has_patch:  1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/28428#comment:9>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/061.e9278b77ef26a62c5a6ed13100116578%40djangoproject.com.