Edgewall Software
Modify

Opened 11 years ago

Closed 7 years ago

Last modified 7 years ago

#11371 closed enhancement (fixed)

Trap IntegrityError when adding and renaming items on ticket admin

Reported by: Ryan J Ollos Owned by: Jun Omae
Priority: normal Milestone: 1.0.17
Component: admin/web Version: 1.0-stable
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Catch IntegrityError when adding new item and renaming item on ticket admin panels.

API Changes:
Internal Changes:

Description (last modified by Ryan J Ollos)

When attempting to add an item that differs from an existing item only by whitespace, the error shown below results. For example, if attempting to add milestone5 , but milestone5 already exists, the traceback results. We should trap this condition and raise the TracError, which is the typical situation when adding an existing item.

How to Reproduce

While doing a POST operation on /admin/ticket/milestones, Trac issued an internal error.

(please provide additional details here)

Request parameters:

{'__FORM_TOKEN': u'366d21614f5d1c6c88ba9da3',
 'add': u'Add',
 'cat_id': u'ticket',
 'duedate': u'11/18/2013 12:00:00 AM',
 'name': u'  milestone5  ',
 'panel_id': u'milestones',
 'path_info': None}

User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/30.0.1599.114 Chrome/30.0.1599.114 Safari/537.36

System Information

Trac 1.1.2dev
Genshi 0.8dev (without speedups)
pysqlite 2.3.2
Python 2.5.6 (r256:88840, Oct 28 2013, 23:50:06)
[GCC 4.7.3]
setuptools 0.6
SQLite 3.7.15.2
jQuery 1.8.3

Enabled Plugins

Python Traceback

Traceback (most recent call last):
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/web/main.py", line 497, in _dispatch_request
    dispatcher.dispatch(req)
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/web/main.py", line 214, in dispatch
    resp = chosen_handler.process_request(req)
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/admin/web_ui.py", line 125, in process_request
    path_info)
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/ticket/admin.py", line 53, in render_admin_panel
    return self._render_admin_panel(req, cat, page, version)
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/ticket/admin.py", line 297, in _render_admin_panel
    mil.insert()
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/ticket/model.py", line 1091, in insert
    to_utimestamp(self.completed), self.description))
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/db/util.py", line 121, in execute
    cursor.execute(query, params)
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/db/util.py", line 65, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/db/sqlite_backend.py", line 78, in execute
    result = PyFormatCursor.execute(self, *args)
  File "/home/user/Workspace/t_component_owner/teo-rjollos.git/trac/db/sqlite_backend.py", line 56, in execute
    args or [])
  File "/home/user/Workspace/t_component_owner/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

Attachments (0)

Change History (18)

comment:2 by Ryan J Ollos, 11 years ago

Also there are some issues mentioned in comment:2:ticket:11351 and comment:4:ticket:11297 that we may want to explore in this ticket.

comment:3 by Ryan J Ollos, 11 years ago

Milestone: next-stable-1.0.x1.0.3

comment:4 by Ryan J Ollos, 11 years ago

Description: modified (diff)

comment:5 by Ryan J Ollos, 10 years ago

Issue reported in SO:23956175.

comment:6 by Ryan J Ollos, 10 years ago

Owner: set to Ryan J Ollos
Status: newassigned

comment:7 by Ryan J Ollos, 10 years ago

Milestone: 1.0.3next-stable-1.0.x
Owner: Ryan J Ollos removed
Status: assignednew

comment:8 by Ryan J Ollos, 10 years ago

See related comment:5:ticket:11351.

comment:9 by Ryan J Ollos, 8 years ago

Milestone: next-stable-1.0.xnext-stable-1.2.x

Moved ticket assigned to next-stable-1.0.x since maintenance of 1.0.x is coming to a close. Please move the ticket back if it's critical to fix on 1.0.x.

comment:10 by strk@…, 7 years ago

I just got hit by this issue too, annoying indeed as it's not easy to see there's a space in the name (dirname is unquoted in trac-admin error message too)

in reply to:  1 comment:11 by Jun Omae, 7 years ago

Replying to Ryan J Ollos:

When attempting to add an item that differs from an existing item only by whitespace, the error shown below results. For example, if attempting to add milestone5 , but milestone5 already exists, the traceback results. We should trap this condition and raise the TracError, which is the typical situation when adding an existing item.

In trac/ticket/admin.py, we trap IntegrityError on saving an item but have not trapped on adding an item for milestone, component, version, enum record.

  • trac/ticket/admin.py

    diff --git a/trac/ticket/admin.py b/trac/ticket/admin.py
    index 06f1273f5..b5b513c77 100644
    a b class MilestoneAdminPanel(TicketAdminPanel):  
    286286                            mil.due = user_time(req, parse_date,
    287287                                                req.args.get('duedate'),
    288288                                                hint='datetime')
    289                         mil.insert()
    290                         add_notice(req, _('The milestone "%(name)s" has been '
    291                                           'added.', name=name))
     289                        try:
     290                            mil.insert()
     291                        except self.env.db_exc.IntegrityError:
     292                            raise TracError(_('Milestone "%(name)s" already '
     293                                              'exists.', name=name))
     294                        else:
     295                            add_notice(req, _('The milestone "%(name)s" has '
     296                                              'been added.', name=name))
    292297                    else:
    293298                        if mil.name is None:
    294299                            raise TracError(_('Invalid milestone name.'))

Proposed changes in [a18914a42/jomae.git] (jomae.git@t11371).

Last edited 7 years ago by Jun Omae (previous) (diff)

comment:12 by Ryan J Ollos, 7 years ago

comment:11 changes look good. For trunk, we'll need to catch ResourceExistsError (#11419).

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

comment:14 by Ryan J Ollos, 7 years ago

The comment:13 changes look good to me.

comment:15 by Jun Omae, 7 years ago

Milestone: next-stable-1.2.x1.0.17
Release Notes: modified (diff)
Resolution: fixed
Status: newclosed

Thanks for the reviewing. Applied in [16502] and merged in [16503-16504].

comment:16 by Jun Omae, 7 years ago

Owner: set to Jun Omae

comment:17 by Ryan J Ollos, 7 years ago

Description: modified (diff)
Summary: Fixup whitespace on repository admin pages when saving changesTrap IntegrityError when adding and renaming items on ticket admin

comment:18 by Ryan J Ollos, 7 years ago

Created #13011 to handle some outstanding issues that were original in description.

comment:19 by Ryan J Ollos, 7 years ago

Added some trac.ticket.model documentation on trunk in r16507.

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.