#3118 closed defect (fixed)
Exception "int argument required" being raised for tickets not in the system when TracError was expected
Reported by: | 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)
Change History (4)
by , 19 years ago
Attachment: | model.diff added |
---|
comment:1 by , 19 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
145 145 for cmd, tkts in cmdGroups: 146 146 if CommitHook._supported_cmds.has_key(cmd.lower()): 147 147 func = getattr(self, CommitHook._supported_cmds[cmd.lower()]) 148 func( ticketPattern.findall(tkts))148 func([int(i) for i in ticketPattern.findall(tkts)]) 149 149 150 150 def _cmdClose(self, tickets): 151 151 for tkt_id in tickets:
comment:2 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Hopefully fixed in r3272, please test.
comment:3 by , 19 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.
Diff for ticket/model.py