Edgewall Software
Modify

Opened 10 years ago

Closed 10 years ago

#12076 closed defect (fixed)

resource_exists in trac.ticket.api should avoid database exceptions from invalid input

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

Tracebacks in log are avoided with PostgreSQL when navigating to the URL /ticket/<id> when <id> is not an integer.

API Changes:

Exceptions are trapped and False returned from trac.ticket.api.TicketSystem.resource_exists when the resource id can't be converted to an integer.

Internal Changes:

Description (last modified by Ryan J Ollos)

Reported in th:#12253, the function resource_exists in trac.ticket.api raises an exception on PostgreSQL when resource.id is not an integer.

Perhaps we should simply try converting resource.id to an integer in resource_exists:

try:
   id_ = int(resource.id)
except ValueError:
   return False

Attachments (0)

Change History (5)

comment:1 by Ryan J Ollos, 10 years ago

Description: modified (diff)
Owner: set to Ryan J Ollos
Status: newassigned

comment:2 by Jun Omae, 10 years ago

I think we should catch both TypeError and ValueError.

>>> from trac.resource import Resource
>>> resource = Resource('ticket')
>>> resource
<Resource 'ticket'>
>>> resource.id is None
True
>>> int(resource.id)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string or a number, not 'NoneType'

in reply to:  2 comment:3 by Ryan J Ollos, 10 years ago

API Changes: modified (diff)
Release Notes: modified (diff)

Replying to jomae:

I think we should catch both TypeError and ValueError.

Thanks. Proposed changes in log:rjollos.git:t12076-resource-exists-trap-exception.

comment:4 by Ryan J Ollos, 10 years ago

Committed to 1.0-stable in [14090], merged to trunk in [14091].

comment:5 by Ryan J Ollos, 10 years ago

Resolution: fixed
Status: assignedclosed

Modify Ticket

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