Edgewall Software
Modify

Opened 4 years ago

Closed 4 years ago

#12604 closed defect (fixed)

Ticket() with invalid ticket id should raise ResourceNotFound rather than ValueError

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'

Attachments (0)

Change History (3)

comment:1 by Jun Omae, 4 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, 'id')
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 id does not exist.
Version 1, edited 4 years ago by Jun Omae (previous) (next) (diff)

comment:2 by Ryan J Ollos, 4 years ago

Changes look good to me.

comment:3 by Jun Omae, 4 years ago

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

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

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae 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.