Opened 22 months ago

Closed 20 months ago

Last modified 8 months ago

#32987 closed New feature (fixed)

Warn user if they attempt to have multiple templatetag libraries with the same name

Reported by: Daniel Owned by: Shreya Bamne
Component: Template system Version: 3.2
Severity: Normal Keywords: template, check
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Daniel)

If a project has mulitple apps with templatetags with the same module name, django will load each of them, but drop all but the last one, and not inform the user at all, making it quite hard to diagnose.

For example, if you have:

  • blog/templatetags/navigation_tags.py
  • news/templatetags/navigation_tags.py
  • pages/templatetags/navigation_tags.py

then try to use them in a template:

{% load navigation_tags %}

then only one of these will be loaded - and there's no report that there is a problem - but if you attempt to use one of the filters / tags from one of the libraries that's not the loaded one, it throws a generic template syntax error saying it's an invalid tag / filter.

Proposed solution:

Add a new 'check' to the django checks that warns the user if there are multiple templatetag libraries with the same name.

see PR:

https://github.com/django/django/pull/14735

Change History (16)

comment:1 Changed 22 months ago by Daniel

Description: modified (diff)
Summary: If multiple apps have templatetags modules with the same name, it silently drops all but one.Warn user if they attempt to have mulitple templatetag libraries with the same name

comment:2 Changed 22 months ago by Mariusz Felisiak

Owner: changed from nobody to Daniel
Status: newassigned
Triage Stage: UnreviewedAccepted

Sounds reasonable.

comment:3 Changed 22 months ago by Jacob Walls

Summary: Warn user if they attempt to have mulitple templatetag libraries with the same nameWarn user if they attempt to have multiple templatetag libraries with the same name

comment:4 Changed 22 months ago by Mariusz Felisiak

Needs documentation: set
Needs tests: set
Patch needs improvement: set

comment:5 Changed 20 months ago by Shreya Bamne

The PR (https://github.com/django/django/pull/14735) mentioned in the ticket was closed due to inactivity. I would like to continue working on this. Would the correct next steps be to assign this ticket to myself, open a new PR and link the old one there? I am new to the Django community, any inputs are appreciated. Thank you.

comment:6 Changed 20 months ago by Shreya Bamne

Owner: changed from Daniel to Shreya Bamne

I have started working on this ticket and assigning the ticket to me.

comment:7 Changed 20 months ago by Shreya Bamne

Continuing on the previous work done on this ticket, here is the link to the new PR: https://github.com/django/django/pull/15005

comment:8 Changed 20 months ago by Mariusz Felisiak

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:9 Changed 20 months ago by Mariusz Felisiak

Needs tests: set
Patch needs improvement: set

comment:10 Changed 20 months ago by Mariusz Felisiak

Needs tests: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:11 Changed 20 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In b98394f:

Refs #32987 -- Refactored out get_template_tag_modules().

comment:12 Changed 20 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 004b4620:

Fixed #32987 -- Added system check for template tag modules with the same name.

Co-authored-by: Daniel Fairhead <daniel@…>

comment:13 Changed 8 months ago by Claude Paroz

I wonder if we should reconsider the new behavior here. The problem is that if in your project dependencies (which make sometimes a big list) you have two tag libraries with the same name, the project won't be able to migrate to Django 4.1. It's rather easily fixable when one of the libs is in your project, but not when they both are from external deps. See https://github.com/jazzband/sorl-thumbnail/issues/713

Could we at least make the check a warning, so it can be silenced?

comment:14 in reply to:  13 Changed 8 months ago by Mariusz Felisiak

Replying to Claude Paroz:

Could we at least make the check a warning, so it can be silenced?

Sounds reasonable, see PR.

comment:15 Changed 8 months ago by GitHub <noreply@…>

In f71b0cf7:

Refs #32987 -- Relaxed system check for template tag modules with the same name by turning into a warning.

Thanks Claude Paroz for the report.

Regression in 004b4620f6f4ad87261e149898940f2dcd5757ef.

comment:16 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 7843c43c:

[4.1.x] Refs #32987 -- Relaxed system check for template tag modules with the same name by turning into a warning.

Thanks Claude Paroz for the report.

Regression in 004b4620f6f4ad87261e149898940f2dcd5757ef.
Backport of f71b0cf769d9ac582ee3d1a8c33d73dad3a770da from main

Note: See TracTickets for help on using tickets.
Back to Top