Django

Code

Ticket #6430 (closed: fixed)

Opened 8 months ago

Last modified 3 months ago

Error when loading templates from Python eggs

Reported by: Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com> Assigned to: nobody
Milestone: Component: Template system
Version: SVN Keywords: eggs
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

egg_template_loader.patch (0.7 kB) - added by Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com> on 01/20/08 21:23:36.
Patch for loading template files from Python eggs
egg_template_loader.2.patch (3.6 kB) - added by Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com> on 01/22/08 00:47:06.
Updated patch for this bug, now includes a test case.

Change History

01/20/08 21:23:36 changed by Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com>

  • attachment egg_template_loader.patch added.

Patch for loading template files from Python eggs

01/20/08 22:44:35 changed by ubernostrum

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests set to 1.
  • needs_docs changed.

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?

01/22/08 00:46:15 changed by Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com>

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.

01/22/08 00:47:06 changed by Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com>

  • attachment egg_template_loader.2.patch added.

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

01/30/08 20:32:36 changed by Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com>

  • needs_tests deleted.

05/06/08 15:36:51 changed by wsmith323

  • 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.

05/29/08 08:11:23 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(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@gmail.com>.


Add/Change #6430 (Error when loading templates from Python eggs)




Change Properties
Action