#21162: regression: changeset e909ceae9b3e72b72e0a2baaa92bba9714f18cd2 breaks 
some
tests for Windows with sqlite
-------------------------------------+-------------------------------------
     Reporter:  manfre               |                    Owner:  ramiro
         Type:  Bug                  |                   Status:  assigned
    Component:  Core (Management     |                  Version:  master
  commands)                          |               Resolution:
     Severity:  Release blocker      |             Triage Stage:
     Keywords:                       |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by ramiro):

 * owner:  nobody => ramiro
 * status:  new => assigned
 * has_patch:  0 => 1


Comment:

 Original committer here.

 This solves both problems:

 {{{
 diff --git a/django/test/testcases.py b/django/test/testcases.py
 index a657530..64a80ab 100644
 --- a/django/test/testcases.py
 +++ b/django/test/testcases.py
 @@ -958,7 +958,8 @@ class FSFilesHandler(WSGIHandler):

      def serve(self, request):
          os_rel_path = self.file_path(request.path)
 -        final_rel_path =
 posixpath.normpath(unquote(os_rel_path)).lstrip('/')
 +        os_rel_path = posixpath.normpath(unquote(os_rel_path))
 +        final_rel_path = os_rel_path.replace('\\', '/').lstrip('/')
          return serve(request, final_rel_path,
 document_root=self.get_base_dir()

      def __call__(self, environ, start_response):
 }}}

 We have historic, deeper inconsistencies, namely:

 1. The file_path() method of contrib.staticfiles StaticFilesHandler
 middleware (and of the django.test.testcases static and media ones
 introduced by my commit too because they are copied from it) changes the
 request path to one with OS-specific path separators (e.g. '/a/b/c.jpg' to
 '\a\b\c.jpg' on Windows.)
 2. That OS-specific path is passed to the respective serve() method where
 it is, among other things, massaged with posixpath.normpath() (note how it
 has no effect on Windows) and then handed to a relevant serve() view
 (django.contrib.staticfiles.views.serve() and django.views.static.serve()
 respectively).
 3. Then the staticfiles serve() view invokes that app's finders machinery
 which consumes OS-specific paths and returns forward-slash delimited
 paths. The newly-introduced middlewares don't do this and this is where
 things diverged because all further processing is done on a OS-specific
 path and as such most of the processing performed by
 django.views.static.serve() has no effect because it expects a
 '/'-delimited path.

 The patch above changes this by using a hack similar to one used by
 django.views.static.serve() to replace '\' with '/' to restore behavior
 parity.

 A longer term project would be to fix (to always consume '/'-delimited
 paths and so make it possible to use that kind of paths through all the
 above described workflow and leave handling of OS-specific ones to the
 finders), formalize and document the (internal, so far undocumented) API
 with staticfiles finders backends, although it might break third party
 backends.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21162#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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.5ad96e600d94e05f77a7697b693ad6d2%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to