Roundup Tracker - Issues

Message8481

Author rouilj
Recipients ThomasAH, ber, rouilj
Date 2026-08-03.00:41:04
Message-id <1785717664.67.0.493775723729.issue2550930@roundup-tracker.org>
In-reply-to
The way I am doing this is to:

  add a @staticmethod called localReplace to templating.py::TemplatingUtils

this defined localReplace(message) and uses static method to keep the same calling
signature (i.e. without self).

In instance.py: change registerUtil(name, func) to see if the name being registered
already exists as an attribute on self.TemplatingUtils. If it does, use setattr to
replace self.TemplatingUtils.name with staticmethod(func).

If the attribute isn't defined, add it to self.templating_utils[name].

Patch attached.

I am a little uncertain about replacing the attribute. registerUtilMethod does the
replacement/overwrite because of the way it's written, but this may be wrong.

I am not sure why the original code is using self.templating_utils[] rather than
just setattr() on the TemplatingUtils class. Is it possible I could contaminate
another thread running against a different tracker (e.g. with wsgi or roundup-server
in thread mode)?

When I added the new definition to self.templating_utils[], the code was still calling the
@staticmethod on TemplatingUtils. If I could invert the resolution order so templating_utils[]
was checked first, then I wouldn't have to setattr on TemplatingUtils.

IIUC __getattr__ is called if __getattribute__ raises an AttributeError and __getattribute__
always looks in self.__dict__ for a match. So maybe I should redefine __getattribute__ to:

    if name in self.client.instance.templating_utils:
        return self.client.instance.templating_utils[name]
    if name in self.__dict__:
        return self.__dict__[name]
    raise AttributeError(name)

Thoughts welcome.
History
Date User Action Args
2026-08-03 00:41:04rouiljsetmessageid: <1785717664.67.0.493775723729.issue2550930@roundup-tracker.org>
2026-08-03 00:41:04rouiljsetrecipients: + rouilj, ber, ThomasAH
2026-08-03 00:41:04rouiljlinkissue2550930 messages
2026-08-03 00:41:04rouiljcreate