Opened 8 years ago

Closed 8 years ago

#27230 closed Bug (wontfix)

Inconsistency in AppConfig.path depending on sys.path

Reported by: vinay karanam Owned by: nobody
Component: Core (Other) Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider the following project structure

root/
    app1/
        __init__.py
        ...
    app2/
        __init__.py
        ...
    project/
        __init__.py
        settings.py
        urls.py
        wsgi.py
    manage.py
    script.py

content of script.py is

import os
import sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

import django
django.setup()

from django.apps import apps


for app in apps.get_app_configs():
    print app.path

If I run python script.py, output will be

$ python script.py
....
/<project_path>/root/app1
/<project_path>/root/app2

If I run ipython script.py, output is

$ ipython script.py
....
app1
app2

Ipython inserts '' as the first entry in sys.path which results in path for project apps being relative path.
This in turn is making the output of django.template.utils.get_app_template_dirs inconsistent.

I faced this issue with python 2.7.11+
This is not an issue with python 2.7.12. I think because of Patch #1739468

Change History (7)

comment:1 by Tim Graham, 8 years ago

As per our support policy, "For each version of Python, only the latest micro release (A.B.C) is officially supported." So perhaps we can close the issue as wontfix unless there's some other argument for making the change?

comment:2 by vinay karanam, 8 years ago

Even with 2.7.12, AppConfig.path will return relative path if I do sys.path.insert(0, '') inside script.py before django.setup()

comment:3 by Tim Graham, 8 years ago

Component: UncategorizedCore (Other)
Summary: Inconsistency in AppConfig.pathInconsistency in AppConfig.path depending on sys.path
Type: UncategorizedBug

Not sure about this right now, but tests aren't passing with the PR.

comment:4 by Aymeric Augustin, 8 years ago

  1. I'm wary of making this backwards-incompatible change.
  2. I think you're hitting this issue because in one case an absolute import is performed and in the other an implicit relative import. IIRC, Python 3 no longer supports the latter, so the resolution is essentially "fixed in Python 3"...

comment:5 by vinay karanam, 8 years ago

I understand this wouldn't be an issue with python 3.
Shouldn't django handle this atleast until it supports python 2.

comment:6 by Aymeric Augustin, 8 years ago

Well, given that the issue doesn't exist in Python 3, is fixed in Django 2.7.12+, and that we're dropping support for Python 2 in six months: https://www.djangoproject.com/weblog/2015/jun/25/roadmap/:

Django 1.11 is likely to be the last version to support Python 2.7 as it will be supported until the end of Python 2 upstream support in 2020.

absent other reasons, it doesn't seem reasonable to me to change the return value of AppConfig.path from a relative to an absolute path, which could cause issues with projects that use this value.

comment:7 by Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top