Opened 17 years ago
Closed 16 years ago
#6430 closed (fixed)
Error when loading templates from Python eggs
Reported by: | 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)
Change History (7)
by , 17 years ago
Attachment: | egg_template_loader.patch added |
---|
comment:1 by , 17 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → 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 by , 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 , 17 years ago
Attachment: | egg_template_loader.2.patch added |
---|
Updated patch for this bug, now includes a test case.
comment:3 by , 17 years ago
Needs tests: | unset |
---|
comment:4 by , 17 years ago
Triage Stage: | Accepted → 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 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch for loading template files from Python eggs