Skip to content

Jinja2Templates assertion error in starlette version >= 0.28 #743

@mkaminsky

Description

@mkaminsky

Problem description

  • Upgrading to FastAPI 0.108.0, allowed for a starlette upgrade to 0.32.0.post1 (previously I was on 0.27.0).
  • Starlette version 0.28 includes this PR, which changes the way that Jinja2Templates() works.
  • The code in Jinja2Templates.__init__() now has an assert directory or env
  • titiler, though, passes in directory="" which python evaluates to False, which triggers the assert
  ...
  File "./main.py", line 9, in <module>
    from titiler.core.errors import DEFAULT_STATUS_CODES, add_exception_handlers
  File "..../lib/python3.11/site-packages/titiler/core/__init__.py", line 5, in <module>
    from . import dependencies, errors, factory, routing  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ..../lib/python3.11/site-packages/titiler/core/factory.py", line 73, in <module>
    DEFAULT_TEMPLATES = Jinja2Templates(
                        ^^^^^^^^^^^^^^^^
  File "..../lib/python3.11/site-packages/starlette/templating.py", line 103, in __init__
    assert directory or env, "either 'directory' or 'env' arguments must be passed"
AssertionError: either 'directory' or 'env' arguments must be passed

Expected Output

No assertion error.

Environment Information

Ubuntu 22.04, python3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions