Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSystemLoader: {% import foo/test %} fails if there are templates 'foo' and 'foo/test' #821

Closed
praiskup opened this issue Mar 14, 2018 · 4 comments · Fixed by #1081
Closed
Labels
Milestone

Comments

@praiskup
Copy link

@praiskup praiskup commented Mar 14, 2018

Consider the FileSystemLoader([dir1, dir2]), where dir1 containers foo template, while dir2 contains directory foo with file test.

Expected Behavior

The env.get_template('foo/test') should return proper template.

Actual Behavior

The env.get_template('foo/test') raises
-> IOError: [Errno 20] Not a directory: 'dir1/foo/test'

Full Traceback

IOError: [Errno 20] Not a directory: 'dir1/foo/test'
>>> from jinja2 import FileSystemLoader, Environment
>>> loader = FileSystemLoader(['dir1', 'dir2'])
>>> env = Environment(loader=loader)
>>> env.get_template('foo/test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/lib/python2.7/site-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/usr/lib/python2.7/site-packages/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "/usr/lib/python2.7/site-packages/jinja2/loaders.py", line 171, in get_source
    f = open_if_exists(filename)
  File "/usr/lib/python2.7/site-packages/jinja2/utils.py", line 154, in open_if_exists
    return open(filename, mode)
IOError: [Errno 20] Not a directory: 'dir1/foo/test'

Your Environment

  • Python version: any
  • Jinja version: any
@praiskup
Copy link
Author

@praiskup praiskup commented Mar 14, 2018

praiskup added a commit to praiskup/distgen that referenced this issue Mar 14, 2018
The projects/postgresql example was moved under tests/dockerfile,
and is up2date.  So for convenience I just added Makefile there.

I noticed issues when the `container` file was presend in `pwd`,
so I reported pallets/jinja/issues/821 and renamed `container`
into `container_opt`.

Resolves: devexp-db#51
@ThiefMaster
Copy link
Member

@ThiefMaster ThiefMaster commented Mar 14, 2018

Interesting.. seems like open_if_exists should check for ENOTDIR as well.

@ThiefMaster
Copy link
Member

@ThiefMaster ThiefMaster commented Mar 14, 2018

Sounds like a good candidate for a PR to fix it (against 2.10-maintenance)

@praiskup
Copy link
Author

@praiskup praiskup commented Mar 14, 2018

Testcase is needed? (btw. yes, ignoring ENOTDIR helps..)

praiskup added a commit to praiskup/jinja that referenced this issue Mar 14, 2018
praiskup added a commit to devexp-db/distgen that referenced this issue Mar 15, 2018
The projects/postgresql example was moved under tests/dockerfile,
and is up2date.  So for convenience I just added Makefile there.

I noticed issues when the `container` file was presend in `pwd`,
so I reported pallets/jinja/issues/821 and renamed `container`
into `container_opt`.

Resolves: #51
praiskup added a commit to praiskup/jinja that referenced this issue Jun 18, 2018
praiskup added a commit to praiskup/jinja that referenced this issue Mar 20, 2019
praiskup added a commit to praiskup/jinja that referenced this issue Mar 20, 2019
praiskup added a commit to praiskup/jinja that referenced this issue May 6, 2019
@davidism davidism added this to the 2.11.0 milestone Oct 13, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
4 participants