Opened 17 years ago

Closed 17 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: dev
Severity: Keywords: eggs
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

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@…> 17 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@…> 17 years ago.
Updated patch for this bug, now includes a test case.

Download all attachments as: .zip

Change History (7)

by Juan Manuel Caicedo <juan.manuel.caicedo@…>, 17 years ago

Attachment: egg_template_loader.patch added

Patch for loading template files from Python eggs

comment:1 by James Bennett, 17 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

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 by Juan Manuel Caicedo <juan.manuel.caicedo@…>, 17 years ago

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.

by Juan Manuel Caicedo <juan.manuel.caicedo@…>, 17 years ago

Attachment: egg_template_loader.2.patch added

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

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

Needs tests: unset

comment:4 by Warren Smith, 17 years ago

Triage Stage: AcceptedReady 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 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: newclosed

(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@…>.

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