How to do a query inside a ticket change listener

10 views
Skip to first unread message

Chris Nelson

unread,
Dec 15, 2010, 4:02:32 PM12/15/10
to trac...@googlegroups.com
In a ticket change listener, I need to get some informatin about another ticket. I could use SQL but I'd rather make sure I don't marry myself to a specific DB. Also, I'd rather not worry about whether the fields I want are custom fields or part of the base ticket and Query takes care of that for me. But Query.execute() needs an Href. I've resorted to:

class DummyReq:
def __init__(self, href):
self.href = href
self.authname = ''

req = DummyReq(Href(''))

...

# Create the Query Object.
query = Query.from_string(self.env, query_string)
# Execute the query. Unique ID should return one row
rows = query.execute(req)

But that's gross. How can I get a req inside a ticket change listener?

Chris
--
Christopher Nelson, Software Engineering Manager
SIXNET - Solutions for Your Industrial Networking Challenges
331 Ushers Road, Ballston Lake, NY  12019
Tel: +1.518.877.5173, Fax: +1.518.877.8346 www.sixnet.com

Remy Blank

unread,
Dec 15, 2010, 4:55:51 PM12/15/10
to trac...@googlegroups.com
> But that's gross. How can I get a req inside a ticket change listener?

The short answer is you can't. There has been some effort to avoid
requiring request objects everywhere, but it seems this hasn't yet
reached the ticket queries. As you have already found out, the query
only needs an Href object, the current authname, and the current timezone.

The Href could be made optional, and if it's missing, no ['href'] item
would be generated. The authname and timezone could be passed as
explicit arguments to count(), execute() and get_sql().

If you can produce a patch that fixes these occurrences of the request
object, I could apply it to trunk.

-- Remy

signature.asc

Chris Nelson

unread,
Dec 16, 2010, 12:06:12 PM12/16/10
to trac...@googlegroups.com
Remy Blank wrote:
>...

> The Href could be made optional, and if it's missing, no ['href'] item
> would be generated. The authname and timezone could be passed as
> explicit arguments to count(), execute() and get_sql().
>
> If you can produce a patch that fixes these occurrences of the request
> object, I could apply it to trunk.

Done (http://trac.edgewall.org/ticket/9935). Thanks.

Reply all
Reply to author
Forward
0 new messages