Code

Opened 6 years ago

Closed 6 years ago

#6430 closed (fixed)

Error when loading templates from Python eggs

Reported by: Juan Manuel Caicedo <juan.manuel.caicedo@…> Owned by: nobody
Component: Template system Version: master
Severity: Keywords: eggs
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The template loader for using templates included in Python eggs (django.template.loaders.eggs.load_template_source) has a bug that raises an exception when a template, thus the loader never finds an existent template and always raises the TemplateDoesNotExist exception.

The bug was introduced in changeset [5609] (see the diff), when the decode function is called on the tuple that should be returned, not on the template string that is returned by the resource_string function.

If the template exists in a egg, instead of return it, an exception is raised with the following message:

  'tuple' object has no attribute 'decode'

I attach here a patch that calls the function correctly.

Attachments (2)

egg_template_loader.patch (676 bytes) - added by Juan Manuel Caicedo <juan.manuel.caicedo@…> 6 years ago.
Patch for loading template files from Python eggs
egg_template_loader.2.patch (3.6 KB) - added by Juan Manuel Caicedo <juan.manuel.caicedo@…> 6 years ago.
Updated patch for this bug, now includes a test case.

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by Juan Manuel Caicedo <juan.manuel.caicedo@…>

Patch for loading template files from Python eggs

comment:1 Changed 6 years ago by ubernostrum

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

Juan, this patch looks right to me, but before it gets marked ready for checkin, could you add some tests to make sure we catch this sort of regression in the future?

comment:2 Changed 6 years ago by Juan Manuel Caicedo <juan.manuel.caicedo@…>

I updated the patch and now includes a test case for this bug, it also includes a minor fix in the template loader.

For the tests I used some mock objects for creating eggs with resources within them. The mock objects deal with some implementation details of the pkg_resources module that could make the test code difficult to read, but I didn't found another way to do this programmatically and without needing to have an specific Python egg installed on the machine that runs the test code.

Feel free to change the code or ask questions about it.

Changed 6 years ago by Juan Manuel Caicedo <juan.manuel.caicedo@…>

Updated patch for this bug, now includes a test case.

comment:3 Changed 6 years ago by Juan Manuel Caicedo <juan.manuel.caicedo@…>

  • Needs tests unset

comment:4 Changed 6 years ago by wsmith323

  • Triage Stage changed from Accepted to Ready for checkin

I emailed Juan and he replied with:

<snip>
I think the patch is done and I'm not working anymore on it. Last
time I checked it worked with the trunk version.

I submitted a test case, I'm not completely satisfied with it but it
still works.
</snip>

Therefore, I'm changing this to "Ready for checkin" in hopes that it really is.

comment:5 Changed 6 years ago by russellm

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

(In [7565]) Fixed #6430 -- Corrected the loading of templates from eggs, which was broken by the unicode merge. Thanks for the excellent report and patch, Juan Manuel Caicedo <juan.manuel.caicedo@…>.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.