Edgewall Software
Modify

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#3118 closed defect (fixed)

Exception "int argument required" being raised for tickets not in the system when TracError was expected

Reported by: cl_111@… Owned by: Jonas Borgström
Priority: low Milestone:
Component: general Version: 0.9.3
Severity: trivial Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

While extending the contrib/trac-post-commit-hook to suit the needs of the company I'm currently employed with, I came across the situation where if a ticket number in the commit log is not actually in the trac system then a int argument required exception is being raised when a TracError exception should be expected.

Example code which triggers the issue (assume ticket 10 does not exist):

from trac.env import open_environment
from trac.ticket import Ticket
from trac.core import TracError


if __name__ == "__main__":
    # Change the following to a ticket number not in your trac project.
    tkt_id = 10

    # Change the following to accordingly
    project = "/var/lib/trac"

    env = open_environment(project)
    try:
        ticket = Ticket(env, tkt_id)
     except TracError, e:
         print>>sys.stderr, 'TracError: %s' % (e)
     except Exception, e:
         print>>sys.stderr, 'Unexpected error while retrieving ticket %s: %s.' % (tkt_id, e)

For a ticket not in the system, what is observed on stderr is the Unexpected error while ... message as opposed to the expected TracError: ... message.

I'll attach a diff which corrects the behaviour for 0.9.3.

Attachments (1)

model.diff (575 bytes ) - added by cl_111@… 18 years ago.
Diff for ticket/model.py

Download all attachments as: .zip

Change History (4)

by cl_111@…, 18 years ago

Attachment: model.diff added

Diff for ticket/model.py

comment:1 by Alec Thomas, 18 years ago

This is a usage bug in whatever is calling the Ticket model constructor. tkt_id is supposed to be an integer, so the exception you are receiving is correct. And in fact, your test script works correctly on my copy of Trac stable (0.9.5).

From looking at trac-post-commit-hook, it seems that this patch should be applied:

  • contrib/trac-post-commit-hook

     
    145145        for cmd, tkts in cmdGroups:
    146146            if CommitHook._supported_cmds.has_key(cmd.lower()):
    147147                func = getattr(self, CommitHook._supported_cmds[cmd.lower()])
    148                 func(ticketPattern.findall(tkts))
     148                func([int(i) for i in ticketPattern.findall(tkts)])
    149149
    150150    def _cmdClose(self, tickets):
    151151        for tkt_id in tickets:

comment:2 by Alec Thomas, 18 years ago

Resolution: fixed
Status: newclosed

Hopefully fixed in r3272, please test.

comment:3 by cl_111@…, 18 years ago

Oops my bad - I copied the wrong version of my test. The tkt_id in my script should have been a string not an integer as follows:

    # Change the following to a ticket number not in your trac project.
    tkt_id = "10"

Anyway your fix to the trac-post-commit-hook does the trick.

Modify Ticket

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