﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6549	Naming templatetag file same as app name can lead to undesired behavior	luftyluft@…	nobody	"In a custom template tag, I am attempting to import a model from a 3rd party app.  The 3rd party app has a templatetag file named the same as the app (app name=coltrane, tag file=coltrane.py)

If I'm correct in my diagnosis, what's happening is that the
django.templatetags package is altering the import path:

{{{
#from django.templatetags.__init__.py
for a in settings.INSTALLED_APPS:
    try:
        __path__.extend(__import__(a + '.templatetags', {}, {},
['']).__path__)
    except ImportError:
        pass

}}}


We have:

{{{
/coltrane
   /templatetags
      coltrane.py
   models.py
   ...
/myapp
  /templatetags
      my_tags.py
}}}


Now when my_tags does an ""from coltrane.models import Link"", I believe
this is occurring within the scope of django.templatetags and hence
our import path looks like:

{{{
(Pdb) import sys
(Pdb) sys.modules['django.templatetags'].__path__
['C:\\Python25\\lib\\site-packages\\django-svn\\django\\templatetags',
'C:\\Python25\\lib\\site-packages\\django-svn\\django\\contrib\\admin\\templatetags', 
'c:\\documents and settings\\brian\\workspace\\tagging\\templatetags', 
'c:\\documents and settings\\brian\\workspace\\lunnova\\apps\\utils\\templatetags', 
'c:\\documents and settings\\brian\\workspace\\coltrane\\templatetags']
}}}


The result is that ""from coltrane import Link"" is winding up in the coltrane
\templatetags directory, seeing the coltrane module and leading to the
undesired behavior of executing there.  I have not seen any
documentation that states that naming templatetag files the same as an
app but it clearly has undesired behavior if a templatetag file tries
to import modules from another app that happens to have a templatetag
file named the same as the app.  I will report this as a bug.  The
workaround is to rename templatetag files so that they don't clash
with the project name, however it seems like django should perhaps
check for this case and warn the developer or else the documentation
should have a clear warning. "		closed	Template system	dev		duplicate	templatetag		Unreviewed	0	0	0	0	0	0
