django-admin-sortable2 icon indicating copy to clipboard operation
django-admin-sortable2 copied to clipboard

django doesn't support pathlib

Open hiaselhans opened this issue 3 years ago • 1 comments

as I discovered recently in https://github.com/django/django/pull/15835 Django does NOT officially support pathlib for template paths.

So i suggest to revert the following commit in the meantime: https://github.com/jrief/django-admin-sortable2/commit/7d0b6616e192dae867c3bf4f9cb8496ab610b5ef

hiaselhans avatar Jul 12 '22 13:07 hiaselhans

and Django is not going to support pathlib.Path in the near future: ticket-33839

hiaselhans avatar Jul 13 '22 07:07 hiaselhans

But the Django source code is full of import pathlib statements. Moreover, all paths specified in settings.py, such as MEDIA_ROOT, STATIC_ROOT, etc. can and shall be of type pathlib.Path, so I really do not understand what you mean with

and Django is not going to support pathlib.Path in the near future:

jrief avatar Aug 11 '22 21:08 jrief

Hi @jrief

did you read the referenced issue? Jinja backend is unable to handle pathlib and the relevant ticket got rejected with the justification that django template is NOT going to support pathlib. Django template backend can also be not filesystem based. Please either reopen the issue or join the discussion on django.

hiaselhans avatar Aug 11 '22 22:08 hiaselhans

@hiaselhans does this mean that django-admin-sortable2 currently does not work with Jinja2 templates?

But this then leads to another question: Who is using Jinja2 templates in the Django admin?

jrief avatar Aug 13 '22 07:08 jrief

@jrief

It means that django-admin-sortable2 does not run when using any other additional template engine that doesn't handle posixpath. nobody is using Jinja for Django admin, but Django template resolution tries the filename with all template engines.

https://github.com/django/django/blob/e30d6678421b7573a1995f61521f14348c9b2a17/django/template/loader.py#L5-L19

def get_template(template_name, using=None):
    """
    Load and return a template for the given name.

    Raise TemplateDoesNotExist if no such template exists.
    """
    chain = []
    engines = _engine_list(using)
    for engine in engines:
        try:
            return engine.get_template(template_name)
        except TemplateDoesNotExist as e:
            chain.append(e)


    raise TemplateDoesNotExist(template_name, chain=chain)

AttributeError("'PosixPath' object has no attribute 'split'") is not catched and thus rendering fails because template resolution order isn't continued.

hiaselhans avatar Aug 13 '22 07:08 hiaselhans