Edgewall Software

Opened 3 years ago

Closed 3 years ago

#12697 closed defect (fixed)

QuerySyntaxError: Query filter requires field and constraints separated by a "="

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.2.1
Component: query system Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Error message is displayed rather than traceback when QuerySyntaxError is raised in TicketQuery macro.

API Changes:


The traceback below appears in the logs when [[TicketQuery(keywords~=firefox&chrome, format=table)]].

See also #12286. I need to review this, but I think we settled on the MacroError pattern:

  • trac/ticket/query.py

    diff --git a/trac/ticket/query.py b/trac/ticket/query.py
    index 1f3fca98c..30d580b46 100644
    a b from trac.web.chrome import (INavigationContributor, Chrome,  
    4646                             add_script_data, add_stylesheet, add_warning,
    4747                             web_context)
    4848from trac.wiki.api import IWikiSyntaxProvider
    49 from trac.wiki.formatter import system_message
     49from trac.wiki.formatter import MacroError
    5050from trac.wiki.macros import WikiMacroBase
    class TicketQueryMacro(WikiMacroBase):  
    13541354            query_string += '&'
    13561356        query_string += '&'.join('%s=%s' % item for item in kwargs.iteritems())
    1357         query = Query.from_string(self.env, query_string)
     1357        try:
     1358            query = Query.from_string(self.env, query_string)
     1359        except QuerySyntaxError as e:
     1360            raise MacroError(e)
    13591362        if format in ('count', 'rawcount'):
    13601363            cnt = query.count(req)
    class TicketQueryMacro(WikiMacroBase):  
    13701373        try:
    13711374            tickets = query.execute(req)
    13721375        except QueryValueError as e:
    1373             self.log.warning(e)
    1374             return system_message(_("Error executing TicketQuery macro"), e)
     1376            raise MacroError(e)
    13761378        if format == 'table':
    13771379            data = query.template_data(formatter.context, tickets,
  • trac/wiki/formatter.py

    diff --git a/trac/wiki/formatter.py b/trac/wiki/formatter.py
    index 7ca620540..9f7efc454 100644
    a b class Formatter(object):  
    794794        try:
    795795            return macro.ensure_inline(macro.process(args))
    796796        except MacroError as e:
    797             return system_message(e)
     797            return system_message(_("Macro %(name)s(%(args)s) failed",
     798                                    name=name, args=args), to_unicode(e))
    798799        except Exception as e:
    799800            self.env.log.error('Macro %s(%s) failed:%s', name, args,
    800801                               exception_to_unicode(e, traceback=True))

With the change, the error message would be:

Error executing TicketQuery macro
Query filter requires field and constraints separated by a "="
[pid 23603 140352200914688] 2017-02-21 11:07:53,460 Trac[formatter] ERROR: Macro TicketQuery(keywords~=firefox&chrome, format=table) failed:
Traceback (most recent call last):
  File "/usr/local/virtualenv/1.3dev/lib/python2.7/site-packages/trac/wiki/formatter.py", line 795, in _macro_formatter
    return macro.ensure_inline(macro.process(args))
  File "/usr/local/virtualenv/1.3dev/lib/python2.7/site-packages/trac/wiki/formatter.py", line 371, in process
    text = self.processor(text)
  File "/usr/local/virtualenv/1.3dev/lib/python2.7/site-packages/trac/wiki/formatter.py", line 343, in _macro_processor
  File "/usr/local/virtualenv/1.3dev/lib/python2.7/site-packages/trac/ticket/query.py", line 1357, in expand_macro
    query = Query.from_string(self.env, query_string)
  File "/usr/local/virtualenv/1.3dev/lib/python2.7/site-packages/trac/ticket/query.py", line 169, in from_string
    raise QuerySyntaxError(_('Query filter requires field and '
QuerySyntaxError: Query filter requires field and constraints separated by a "="

Attachments (0)

Change History (3)

comment:1 by Peter Suter, 3 years ago

(FWIW: I was trying to remember how this hidden feature works:

  • firefox: 14
  • chrome: 14
  • firefox & chrome: 1
  • firefox -chrome: 13
  • chrome -firefox: 13

But I had to search for #10152 instead.)

Last edited 3 years ago by Peter Suter (previous) (diff)

comment:2 by Ryan J Ollos, 3 years ago

comment:3 by Ryan J Ollos, 3 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed to 1.2-stable in r15563, merged to trunk in r15564.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to as closed The owner will be changed from Ryan J Ollos to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.