views:

33

answers:

2

Hello ! I am obviously victim of some dark magic...

Here is a template that I render :

context = Context({'my_cube': c})
template = Template(
    '{% load cube_templatetags %}'
    '{{ my_cube|inspect }} {{ my_cube.measure }}'
)

Here is the implementation of the inspect filter :

def inspect_object(obj):
    return obj.measure()

Here is what the rendering gives me :

>>> template.render(context)
u'6 None'

Does anyone know why the hell does the {{ my_cube.measure }} is not rendered properly, while obviously the function call is successful ???

NB : the measure function does no magic, no internal state is changed, I tested and it gives the same result each time, I also tested to put the inspect before the {{ cube.measure }}.... doesn't change anything. I have absolutely no clue on what's going on...

EDIT : I know where it seems to be coming from. But it is still strange. For some reason, my object's attribute are not resolved by template.Variable :

>>> Variable('measure').resolve(c) == None
True
>>> Variable('testitesti').resolve(c) == None
True
>>> c.testitesti()
68
#implementation of testitesti :
def testitesti(self):
    return 68
A: 

Inspect is being registered as a filter, yep? I'm assuming so else the whole template would choke. Is there a possible reserved word clash? inspect is a pretty loaded term, after all. Have you tried renaming that filter to something else?

stevejalim
Actually, this 'inspect' filter is just a debug filter that I wrote, after I observed the bug before... Plus, it would be a weird coincidence that there is a clash of names, but .... tadaaaa : I am still getting the expected value ! But I try ...
sebpiq
yep ... same thing if I call the filter 'my_super_unique_inspect' !!!
sebpiq
+2  A: 

Well... I found the damn thing !

The object I was trying to render had a __getitem__ method that was just empty, so dictionnary indexing worked on this object (no error thrown), so of course the function call was not made !

sebpiq