The automatic configuration of settings.TEMPLATES adds Django's cached loader as child loader.
It seem like the cached Loader is meant to be used only as a top level loader. If used as a child loader it passes calls directly to it's children, bypassing the caching mechanism. We noticed a considerable increase in our CI test time once we introduced it.
The engine calls the top loader get_template method
Not entirely sure how to work around or fix the issue. The Django test cases for the loaders don't seem to go beyond one level of nesting so it doesn't feel like it's something planned for. I just skimmed them so I might have overlooked something. It does feel quite unintuitive and a missed opportunity if that's the case.
The automatic configuration of
settings.TEMPLATES
adds Django's cached loader as child loader.It seem like the cached Loader is meant to be used only as a top level loader. If used as a child loader it passes calls directly to it's children, bypassing the caching mechanism. We noticed a considerable increase in our CI test time once we introduced it.
get_template
and callssuper().get_template
https://github.com/carltongibson/django-template-partials/blob/71128aab3007be18e56f761509e6d536a5378c51/src/template_partials/loader.py#L37template_partials
Loader theget_template_sources
forwards the calls down it's child loaders https://github.com/carltongibson/django-template-partials/blob/71128aab3007be18e56f761509e6d536a5378c51/src/template_partials/loader.py#L56-L58get_templates
https://github.com/django/django/blob/4636baec179d8733e92c1eccfa669bd72d739735/django/template/loaders/cached.py#L68-L70filesystem.Loader
that will return the templateOrigin
https://github.com/django/django/blob/4636baec179d8733e92c1eccfa669bd72d739735/django/template/loaders/filesystem.py#L27-L45get_template
This is a simple test case showing the behavior.
Not entirely sure how to work around or fix the issue. The Django test cases for the loaders don't seem to go beyond one level of nesting so it doesn't feel like it's something planned for. I just skimmed them so I might have overlooked something. It does feel quite unintuitive and a missed opportunity if that's the case.