[Django] #30694: FileResponse does not seek its file source

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

[Django] #30694: FileResponse does not seek its file source

Django
#30694: FileResponse does not seek its file source
-----------------------------------------+------------------------
               Reporter:  Claude Paroz   |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  HTTP handling  |        Version:  2.2
               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              |
-----------------------------------------+------------------------
 I'm not sure this is a bug, but I was bitten by some code today:

 {{{
 buffer = io.BytesIO()
 buffer.write(b'some binary content')
 return FileResponse(buffer, filename='somename.bin')
 }}}
 and the response is empty because the stream position is at the end of the
 buffer. I can easily fix that by seeking the buffer myself, but shouldn't
 `FileResponse` seek itself in `_set_streaming_content` before calling
 `filelike.read`?

--
Ticket URL: <https://code.djangoproject.com/ticket/30694>
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/050.868d5f3ce013a3ddf0d61f664826ccc0%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30694: FileResponse does not seek its file source

Django
#30694: FileResponse does not seek its file source
-------------------------------+--------------------------------------
     Reporter:  Claude Paroz   |                    Owner:  nobody
         Type:  Bug            |                   Status:  closed
    Component:  HTTP handling  |                  Version:  2.2
     Severity:  Normal         |               Resolution:  wontfix
     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 Carlton Gibson):

 * status:  new => closed
 * resolution:   => wontfix


Comment:

 Hi Claude.

 > ...shouldn't FileResponse seek itself ...

 I think not here.

 I imagine a situation where you want to tail a log, say. You can't do that
 if we reset the stream position ourselves.

 I then think that resetting the stream makes `FileResponse` a little bit
 too clever. (Happy if someone wants to put that in a subclass, but it's
 beyond "take a buffer, stream it to an HTTP response", which is what I
 take to be the limit of the scope here.)

 So, for me, the maxim in play is, "You pass an open file. Your
 responsibility to `seek` accordingly".

 As such, I'm going to go with `wontfix`. I hope that makes sense.

 **Maybe** an addition to the FileResponse docs?

 > ...`streaming_content` begins from the current cursor position of
 `open_file`...

 (Or such, somewhere.)

--
Ticket URL: <https://code.djangoproject.com/ticket/30694#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 view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.9d1e68295affdcda8730cea52c487828%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30694: Document FileResponse does not seek its file source (was: FileResponse does not seek its file source)

Django
In reply to this post by Django
#30694: Document FileResponse does not seek its file source
-------------------------------+--------------------------------------
     Reporter:  Claude Paroz   |                    Owner:  nobody
         Type:  Bug            |                   Status:  closed
    Component:  Documentation  |                  Version:  2.2
     Severity:  Normal         |               Resolution:  wontfix
     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 Claude Paroz):

 * component:  HTTP handling => Documentation


Comment:

 Something like that?:
 {{{
 diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
 index 19593dfb90..3dfbf28cf6 100644
 --- a/docs/ref/request-response.txt
 +++ b/docs/ref/request-response.txt
 @@ -1122,6 +1122,8 @@ Attributes

      If ``open_file`` doesn't have a name or if the name of ``open_file``
 isn't
      appropriate, provide a custom file name using the ``filename``
 parameter.
 +    Note that if you pass a file-like object like ``io.BytesIO``, it's
 your
 +    task to ``seek()`` it before passing it to ``FileResponse``.

      The ``Content-Length`` and ``Content-Type`` headers are automatically
 set
      when they can be guessed from contents of ``open_file``.
 }}}
 I suspect the example in https://docs.djangoproject.com/en/2.2/howto
 /outputting-pdf/#write-your-view is missing the seek call.

--
Ticket URL: <https://code.djangoproject.com/ticket/30694#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 view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.156d3067e2025379c6a127750615a8a2%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30694: Document FileResponse does not seek its file source

Django
In reply to this post by Django
#30694: Document FileResponse does not seek its file source
-------------------------------+------------------------------------
     Reporter:  Claude Paroz   |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  Documentation  |                  Version:  2.2
     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 Carlton Gibson):

 * status:  closed => new
 * resolution:  wontfix =>
 * stage:  Unreviewed => Accepted


Comment:

 Yep, I'll take that. Perfect. 🙂

--
Ticket URL: <https://code.djangoproject.com/ticket/30694#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 view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.d715f1390b10bf67a2f3db5271f3a11b%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30694: Document FileResponse does not seek its file source

Django
In reply to this post by Django
#30694: Document FileResponse does not seek its file source
-------------------------------+------------------------------------
     Reporter:  Claude Paroz   |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  Documentation  |                  Version:  2.2
     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


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/30694#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 view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.82a9467c78e648e02e664b14269809ad%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30694: Document FileResponse does not seek its file source

Django
In reply to this post by Django
#30694: Document FileResponse does not seek its file source
-------------------------------+------------------------------------
     Reporter:  Claude Paroz   |                    Owner:  nobody
         Type:  Bug            |                   Status:  closed
    Component:  Documentation  |                  Version:  2.2
     Severity:  Normal         |               Resolution:  fixed
     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 Carlton Gibson <carlton.gibson@…>):

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


Comment:

 In [changeset:"7203efb799969b4662ecb58f4cefd2a5f2e0062b" 7203efb7]:
 {{{
 #!CommitTicketReference repository=""
 revision="7203efb799969b4662ecb58f4cefd2a5f2e0062b"
 Fixed #30694 -- Documented FileResponse does not seek its file source.
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30694#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 view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.333343db95cb508c0af7e19e873aa8f1%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30694: Document FileResponse does not seek its file source

Django
In reply to this post by Django
#30694: Document FileResponse does not seek its file source
-------------------------------+------------------------------------
     Reporter:  Claude Paroz   |                    Owner:  nobody
         Type:  Bug            |                   Status:  closed
    Component:  Documentation  |                  Version:  2.2
     Severity:  Normal         |               Resolution:  fixed
     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 Carlton Gibson <carlton.gibson@…>):

 In [changeset:"556cef1ba8facbd3231f6351956a6581c6367632" 556cef1]:
 {{{
 #!CommitTicketReference repository=""
 revision="556cef1ba8facbd3231f6351956a6581c6367632"
 [2.2.x] Fixed #30694 -- Documented FileResponse does not seek its file
 source.

 Backport of 7203efb799969b4662ecb58f4cefd2a5f2e0062b from master
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30694#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/065.2185df00c33d695d869caaa3d5f013cf%40djangoproject.com.