Edgewall Software

Opened 8 years ago

Closed 8 years ago

#12604 closed defect (fixed)

Ticket() with invalid ticket id should raise ResourceNotFound rather than ValueError — at Version 3

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.0.14
Component: ticket system Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Raise ResourceNotFound when passing non-integer to Ticket().

API Changes:
Internal Changes:

Description

I got the following error in my production environment. It seems the user try to use ticket.get('id') via JSON-RPC.

2016-08-25 09:04:09,725 (7f0946c09700) ERROR: RPC(JSON-RPC) Error
Traceback (most recent call last):
  File "/vol/releases/20160818034305/share/plugins/TracXMLRPC.egg/tracrpc/web_ui.py", line 155, in _rpc_process
    result = (XMLRPCSystem(self.env).get_method(method_name)(req, args))[0]
  File "/vol/releases/20160818034305/share/plugins/TracXMLRPC.egg/tracrpc/api.py", line 209, in __call__
    result = self.callable(req, *args)
  File "/vol/releases/20160818034305/share/plugins/TracXMLRPC.egg/tracrpc/ticket.py", line 158, in get
    t = model.Ticket(self.env, id)
  File "/usr/local/tracfarm/lib/python2.6/site-packages/trac/ticket/model.py", line 69, in __init__
    tkt_id = int(tkt_id)
ServiceException: invalid literal for int() with base 10: 'id'

I consider Ticket() passed invalid ticket id should raise ResourceNotFound rather than ValueError.

>>> from trac.test import EnvironmentStub
>>> from trac.ticket.model import Ticket
>>> env = EnvironmentStub()
>>> t = Ticket(env, 'id')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/venv/trac/1.0.13/lib/python2.5/site-packages/trac/ticket/model.py", line 69, in __init__
    tkt_id = int(tkt_id)
ValueError: invalid literal for int() with base 10: 'id'

Change History (3)

comment:1 by Jun Omae, 8 years ago

Owner: set to Jun Omae
Status: newassigned

Proposed changes in [96864b590/jomae.git] (jomae.git@t12604).

After the changes:

>>> from trac.test import EnvironmentStub
>>> from trac.ticket.model import Ticket
>>> env = EnvironmentStub()
>>> t = Ticket(env, 'blah')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "trac/ticket/model.py", line 85, in __init__
    self._fetch_ticket(tkt_id)
  File "trac/ticket/model.py", line 126, in _fetch_ticket
    id=tkt_id), _("Invalid ticket number"))
trac.resource.ResourceNotFound: Ticket blah does not exist.
Last edited 8 years ago by Jun Omae (previous) (diff)

comment:2 by Ryan J Ollos, 8 years ago

Changes look good to me.

comment:3 by Jun Omae, 8 years ago

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

Thanks for the reviewing. Committed in [15172] and merged in [15173-15174].

Note: See TracTickets for help on using tickets.