#23436: Should use abspath for default settings.BASE_DIR
--------------------------------------+--------------------
     Reporter:  hjwp                  |      Owner:  nobody
         Type:  Cleanup/optimization  |     Status:  new
    Component:  Uncategorized         |    Version:  1.6
     Severity:  Normal                |   Keywords:
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  0                     |      UI/UX:  0
--------------------------------------+--------------------
 ref the default project template's settings.py, BASE_DIR is defined as:

 {{{
 BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 }}}

 Because there's no abspath, you can get different results for BASE_DIR
 depending on how settings.py is run.  This is an edge case, since
 settings.py is almost always imported by django in the right context, but
 still -- compare:

     python manage.py shell
     >>> from django.conf import settings
     print(BASE_DIR)

 With:

     python -i myproject/settings.py
     >>> print(BASE_DIR)

 As an aside, in general, in any path wrangling you should always call
 abspath first. Try running this script, saved to a file:

     import os
     print(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
     print(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

 As to tests, the only one I can think of would be a pretty horrible one
 involving actually callling out using subprocess.Popen to a python -i of
 the project template settings file, so maybe ok not to bother?

 credit to @CleanCut for turning me onto this weirdness!

--
Ticket URL: <https://code.djangoproject.com/ticket/23436>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/047.dbd4365ea4b9c3af41fa39a1d4bc2352%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to