Edgewall Software

Opened 10 years ago

Last modified 4 years ago

#11419 closed enhancement

More user-friendly error message from trac-admin console commands when IntegrityError in database — at Version 9

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.3.2
Component: admin/console Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Cached fields returned by TicketSystem.get_ticket_fields were not updated when milestone due or completed dates were changed.

API Changes:
Internal Changes:

Description

Console admin milestone add operation could report a nicer error when milestone already exists. For example,

$ trac-admin tracdev milestone add milestone1
IntegrityError: column name is not unique
16:29:47 Trac[console] ERROR: Exception in trac-admin command: 
Traceback (most recent call last):
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/admin/console.py", line 110, in onecmd
    rv = cmd.Cmd.onecmd(self, line) or 0
  File "/usr/lib/python2.7/cmd.py", line 220, in onecmd
    return self.default(line)
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/admin/console.py", line 286, in default
    return self.cmd_mgr.execute_command(*args)
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/admin/api.py", line 127, in execute_command
    return f(*fargs)
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/ticket/admin.py", line 411, in _do_add
    milestone.insert()
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/ticket/model.py", line 1042, in insert
    to_utimestamp(self.completed), self.description))
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/db/util.py", line 121, in execute
    cursor.execute(query, params)
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/db/util.py", line 65, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/db/sqlite_backend.py", line 78, in execute
    result = PyFormatCursor.execute(self, *args)
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/db/sqlite_backend.py", line 56, in execute
    args or [])
  File "/home/user/Workspace/t2311/teo-rjollos.git/trac/db/sqlite_backend.py", line 48, in _rollback_on_error
    return function(self, *args, **kwargs)
IntegrityError: column name is not unique

Instead, we'll aim for something like:

$ trac-admin tracdev milestone add milestone1
TracError: milestone "milestone1" already exists

Change History (9)

comment:1 by Jun Omae, 10 years ago

Sorry, I've misunderstood. Please Ignore it.

Trac 1.0 and 1.0.1 don't show backstrace of the errors.

$ ~/venv/trac/1.0/bin/trac-admin ~/var/trac/1.0 milestone add milestone1
IntegrityError: column name is not unique
$ ~/venv/trac/1.0.1/bin/trac-admin ~/var/trac/1.0 milestone add milestone1
IntegrityError: column name is not unique
Last edited 10 years ago by Jun Omae (previous) (diff)

comment:2 by Ryan J Ollos, 9 years ago

Owner: set to Ryan J Ollos
Status: newassigned

comment:3 by Ryan J Ollos, 9 years ago

Milestone: 1.0.31.1.3

comment:4 by Ryan J Ollos, 9 years ago

Milestone: 1.1.31.1.4

This ticket has led to a pretty extensive refactoring that I haven't finished yet. I committed a few of the simple changes in [13621,13624,13625]. The rest will need to wait for 1.1.4.

comment:5 by Jun Omae, 9 years ago

The changes in [13621] have an issue which cached TicketSystem.fields should be reset when Version.time is updated. I think the changes should be reverted.

Trac 1.1.2:

>>> from trac import __version__
>>> print __version__
1.1.2
>>> from datetime import datetime
>>> from trac.test import EnvironmentStub
>>> from trac.ticket.api import TicketSystem
>>> from trac.ticket.model import Version
>>> from trac.util.datefmt import utc
>>> env = EnvironmentStub(default_data=True)
>>> tktsys = TicketSystem(env)
>>> [f['options'] for f in tktsys.fields if f['name'] == 'version']
[[u'2.0', u'1.0']]
>>> versions = Version.select(env)
>>> [v.name for v in versions]
[u'2.0', u'1.0']
>>> versions[0].time = datetime(2014, 1, 1, tzinfo=utc)
>>> versions[0].update()
>>> versions[1].time = datetime(2014, 2, 1, tzinfo=utc)
>>> versions[1].update()
>>> [v.name for v in Version.select(env)]
[u'1.0', u'2.0']
>>> [f['options'] for f in tktsys.fields if f['name'] == 'version']
[[u'1.0', u'2.0']]

Trac 1.1.3dev after [13621]:

>>> from trac import __version__
>>> print __version__
1.1.3dev
>>> from datetime import datetime
>>> from trac.test import EnvironmentStub
>>> from trac.ticket.api import TicketSystem
>>> from trac.ticket.model import Version
>>> from trac.util.datefmt import utc
>>> env = EnvironmentStub(default_data=True)
>>> tktsys = TicketSystem(env)
>>> [f['options'] for f in tktsys.fields if f['name'] == 'version']
[[u'2.0', u'1.0']]
>>> versions = Version.select(env)
>>> [v.name for v in versions]
[u'2.0', u'1.0']
>>> versions[0].time = datetime(2014, 1, 1, tzinfo=utc)
>>> versions[0].update()
>>> versions[1].time = datetime(2014, 2, 1, tzinfo=utc)
>>> versions[1].update()
>>> [v.name for v in Version.select(env)]
[u'1.0', u'2.0']
>>> [f['options'] for f in tktsys.fields if f['name'] == 'version']
[[u'2.0', u'1.0']]  # <== should be reset

comment:6 by Ryan J Ollos, 9 years ago

I'll add a unit test for that and revert the one-line change to the Version class. I won't revert the other changes unless you see a problem with them. Thanks for noticing.

comment:7 by Jun Omae, 9 years ago

Seems that Milestone class has the same issue, which is introduced in [9692].

comment:8 by Ryan J Ollos, 9 years ago

Thanks, that's a good find and I'll fix that issue as well. In the changes I've been preparing for this ticket I've added extensive unit test coverage, but I didn't consider the cached ordering for either Version or Milestone in the TicketSystem fields. It will be good to add unit-test coverage for those cases.

Last edited 9 years ago by Ryan J Ollos (previous) (diff)

comment:9 by Ryan J Ollos, 9 years ago

Release Notes: modified (diff)

Issues from comment:5 and comment:7 fixed in [13626], merged in [13627].

Note: See TracTickets for help on using tickets.