Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#13311 closed (fixed)

Template Tag modules that raise an ImportError are difficult to debug

Reported by: amccurdy Owned by: nobody
Component: Template system Version: 1.2-beta
Severity: Keywords: templatetag library
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I have several template tag libraries that I register using the add_to_builtins function. While upgrading to Django 1.2, I found that one of these template tag libraries was raising an ImportError. The ImportError was hidden from me however, because django.template.import_library catches ImportError and simply returns None. The None value still gets added to the django.template.builtins module-level variable, which eventually ends up making it's way to the Parser class's add_library function. Parser.add_library references the .tags attribute without checking for None, raising an AttributeError. There's was no indication of which template tag library caused the error, making this a pain to track down.

I would suggest that django.template.import_library not mask the ImportError. If this breaks backwards compatibility, then at least raise the ImportError from django.template.add_to_builtins.

Change History (3)

comment:1 Changed 5 years ago by russellm

  • milestone set to 1.2
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Agreed that masking the import error is less than ideal. Accepting to 1.2 milestone because it's in an area that has changed significantly in 1.2, and we need to make sure that debugging info doesn't get any worse by upgrading.

comment:2 Changed 5 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [12944]) Fixed #13311 -- Modified the tag library import process so it doesn't mask import errors in the tag library itself. Thanks to amccurdy for the report, and Alex Gaynor for the suggested fix.

comment:3 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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