#88 closed enhancement (fixed)
No error given on use of non existent variable
Reported by: | james | Owned by: | cmlenz |
---|---|---|---|
Priority: | major | Milestone: | 0.4 |
Component: | Expression evaluation | Version: | 0.3.5 |
Keywords: | Cc: | james.harris@… |
Description
e.g.
if in a template I have ${foo} but foo isn't in the dictionary returned from the controller, I would expect an error message - KeyError? or some such -but instead ${foo} is just ignored
Attachments (1)
Change History (15)
comment:1 follow-up: ↓ 2 Changed 18 years ago by mgood
comment:2 in reply to: ↑ 1 Changed 18 years ago by anonymous
comment:3 Changed 18 years ago by jochen.kupperschmidt@…
Actually, unlike other "scripting languages" (take a look at http://www.sitepoint.com/blogs/2006/07/27/how-strict-is-your-dynamic-language/), Python complains about stuff like missing variables and interrupts by throws exceptions. It would be just consequent to extend this behaviour to Python packages, including Genshi.
OTOH, it would presumably break templates here and there (I can remember at least one situation that made me wonder about missing variables in template context). Especially complex application conditions would make it hard to spot affected template parts. Automatic upgrades oder new setups of applications unaware of ths would suddenly break them. But hey, CHANGELOG is there for a reason.
Personally, I am unsure what to do about this. The first point makes sense, but backwards compatiblity saves some trouble. But if it should be changed, the sooner the better.
comment:4 Changed 18 years ago by jharris
I started discussing this at http://groups.google.com/group/genshi/browse_thread/thread/73b45ddb2ce7aa5b if anybody is still interested :)
comment:5 Changed 18 years ago by anonymous
- Cc james.harris@… added
comment:6 follow-up: ↓ 7 Changed 18 years ago by cmlenz
- Component changed from General to Expression evaluation
- Status changed from new to assigned
- Type changed from defect to enhancement
I've added a patch that removes the Undefined magic from expression evaluation. When accessing undefined names, or trying to accessing attributes/items that don't exist, an UndefinedError will be raised, instead of an Undefined object being returned.
At this point, I'm personally convinced that the lenient error handling in Genshi was a bad design decision, and would like to get rid of it. Backwards compatibility is my greatest concern about the change (as in: things will break). I'm against making this behavior configurable, though.
comment:7 in reply to: ↑ 6 ; follow-up: ↓ 8 Changed 18 years ago by cboos
Replying to cmlenz:
Backwards compatibility is my greatest concern about the change (as in: things will break).
Well, maybe you can have a try with Trac 0.11dev and see if there are not to many changes required. For now it breaks directly at the layout.html level, so maybe it's better if you have a look.
I'm against making this behavior configurable, though.
I've no big problem with the change, it's probably true that this will help us to catch more errors beforehand. I just hope it won't be too much work at this point (keep fingers crossed!).
comment:8 in reply to: ↑ 7 ; follow-up: ↓ 9 Changed 18 years ago by cmlenz
Replying to cboos:
Well, maybe you can have a try with Trac 0.11dev and see if there are not to many changes required. For now it breaks directly at the layout.html level, so maybe it's better if you have a look.
Right, Trac is an example of a code base that makes extensive use of this behavior. I've already started testing & fixing many problems.
comment:9 in reply to: ↑ 8 Changed 18 years ago by cboos
Replying to cmlenz:
Replying to cboos:
Well, maybe you can have a try with Trac 0.11dev and see if there are not to many changes required. For now it breaks directly at the layout.html level, so maybe it's better if you have a look.
Right, Trac is an example of a code base that makes extensive use of this behavior. I've already started testing & fixing many problems.
That's great! I think there shouldn't be any problem if you commit those changes as you go, as the fixed python code and genshi templates should still be compatible with Genshi 0.3.6, right?
There's one occurrence of direct use of Undefined which I could take care of, if you want.
comment:10 Changed 18 years ago by michele
+1 for adopting this behavior by default.
comment:11 Changed 18 years ago by cmlenz
- Resolution set to fixed
- Status changed from assigned to closed
Patch with minor enhancements applied in [510]. Lots of documentation to update still.
comment:12 Changed 18 years ago by nautical9@…
Seems there are a few more places in Trac that this update breaks:
- trac/ticket/templates/ticket.html:159 (... has no member named "preview")
- trac/versioncontrol/templates/changeset.html:81 (... has no member named "path")
(there was at least one more I ran into but forgot to record before I figured out what the problem was, sorry).
(And sorry if this is in the wrong tracker - I couldn't find a ticket on the Trac side).
comment:13 Changed 18 years ago by cboos
Yeah, as it seems there is much work left, and as tickets began to pour in, I created a stabilization branch (trac:source:sandbox/genshi510), and trunk should be usable with Genshi r509.
This is intentional to avoid spurious errors if you missed adding a variable to the context (see r377).