Discussion:
[Trac-dev] How to best store plugin per-request-scoped state?
Patrick Schaaf
2017-09-02 08:35:33 UTC
Permalink
Hi trac devs,

quick question: what's the best way for a plugin to store some state
with per-request lifetime? Ideally for whatever trac version that's
running? :-)

concretely, I just noticed the IncludePages macro from trac-hacks, on
my 0.11 install (yes, I know, ancient), going into a neverending CPU
burning loop when used on a page X and including page X itself..... so
I want to put some recursion protection (a dict of pages walked during
the current request) into the code. This has to go into the " def
expand_macro(self, formatter, name, txt):" and work with state
available there.

So, is there such a best way to do it?

best regards & thanks in advance
Patrick
--
You received this message because you are subscribed to the Google Groups "Trac Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-dev+***@googlegroups.com.
To post to this group, send email to trac-***@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.
RjOllos
2017-09-04 22:12:02 UTC
Permalink
Post by Patrick Schaaf
Hi trac devs,
quick question: what's the best way for a plugin to store some state
with per-request lifetime? Ideally for whatever trac version that's
running? :-)
concretely, I just noticed the IncludePages macro from trac-hacks, on
my 0.11 install (yes, I know, ancient), going into a neverending CPU
burning loop when used on a page X and including page X itself..... so
I want to put some recursion protection (a dict of pages walked during
the current request) into the code. This has to go into the " def
expand_macro(self, formatter, name, txt):" and work with state
available there.
So, is there such a best way to do it?
You could just add an attribute to the request object.

req = formatter.req
if not hasattr(req, 'pages_walked'):
req.pages_walked = {}

- Ryan
--
You received this message because you are subscribed to the Google Groups "Trac Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-dev+***@googlegroups.com.
To post to this group, send email to trac-***@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.
Loading...