Edgewall Software

Opened 17 years ago

Closed 17 years ago

#158 closed defect (fixed)

Unexpected "undefined" error

Reported by: cboos Owned by: cmlenz
Priority: major Milestone: 0.5
Component: Expression evaluation Version: devel
Keywords: Cc:

Description

While stress-testing Trac, I sometimes get weird Genshi errors, using a fairly recent build (0.5dev-r766, well, that's the latest even).

KeyError: <Undefined 'name'>

and the one line backtrace is:

 File "...\trunk\trac\ticket\templates\query_results.html", line 48, in  <Suite u'name = header.name; value = result[name]'>  

The actual line content is:

 <py:with vars="name = header.name; value = result[name]">

The data section shows the following for header (with less truncation than usual in order to get the full representation):

header  	{'href': '/devel/query?group=status&order=owner&milestone=This+is+a+stupid+milestone', 'name': 'owner', 'label': 'Owner'}

As you can see, there's an entry for 'name' here.

Needless to say, when reloading the page after the error, it displays just fine, so it's really a transient error triggered by the testing conditions and probably due to some race condition.

Just another thought: line 47 is

<py:for each="idx, header in enumerate(headers)" py:choose="">

so perhaps it's a bug in enumerate... but that would be scary as well!

How to reproduce

Start tracd, in a new firefox window, open something like twenty tabs, half of them custom query views. Restart tracd. "Load all tabs". If you're lucky, one of the custom query view will show the above backtrace.

Change History (3)

comment:1 in reply to: ↑ description Changed 17 years ago by cboos

  • Version changed from 0.4.4 to devel

Correction:

How to reproduce ...

Restart tracd. "Load all tabs".

The "restart" is actually not needed in order to reproduce the problem.

comment:2 Changed 17 years ago by cboos

This makes the problem go away:

  • genshi/template/eval.py

     
    7373            lookup = LenientLookup
    7474        elif isinstance(lookup, basestring):
    7575            lookup = {'lenient': LenientLookup, 'strict': StrictLookup}[lookup]
    76         self._globals = lookup.globals()
     76        self._globals = lookup.globals
    7777
    7878    def __eq__(self, other):
    7979        return (type(other) == type(self)) and (self.code == other.code)
     
    139139        :return: the result of the evaluation
    140140        """
    141141        __traceback_hide__ = 'before_and_this'
    142         _globals = self._globals
     142        _globals = self._globals()
    143143        _globals['data'] = data
    144144        return eval(self.code, _globals, {'data': data})
    145145
     
    161161        :param data: a mapping containing the data to execute in
    162162        """
    163163        __traceback_hide__ = 'before_and_this'
    164         _globals = self._globals
     164        _globals = self._globals()
    165165        _globals['data'] = data
    166166        exec self.code in _globals, data
    167167

Now the real challenge would be to write a unit-test for that ;-)

comment:3 Changed 17 years ago by cmlenz

  • Resolution set to fixed
  • Status changed from new to closed

Applied in [770]. Thanks!

Note: See TracTickets for help on using tickets.