dupe_keys errors for sqlite are not handle correctly

Bug #1458583 reported by Nikolay Makhotkin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.db
Confirmed
Medium
Unassigned

Bug Description

When we have a lot of unique constraints columns and try to add object twice - somehow we see

"oslo_db.exception.DBError: (IntegrityError) UNIQUE constraint failed u'INSERT INTO ..."

This bug is mostly related to https://bugs.launchpad.net/oslo.db/+bug/1386145 .

Need to add one more regexp in sqlite_dupe_key_filter, existing filters don't match to error text:

https://github.com/openstack/oslo.db/blob/master/oslo_db/sqlalchemy/exc_filters.py#L155-L157

More details about this error: http://logs.openstack.org/70/185370/1/check/gate-mistral-python27/b2518dc/console.html#_2015-05-25_13_01_30_545

Steps to reproduce:

>>> from oslo.db.sqlalchemy import session
>>> eng = session.create_engine('sqlite://')
>>> expr = """CREATE TABLE cron_triggers_v2 (
... created_at DATETIME,
... updated_at DATETIME,
... scope VARCHAR(80),
... project_id VARCHAR(80),
... id VARCHAR(36) NOT NULL,
... name VARCHAR(200),
... pattern VARCHAR(100),
... next_execution_time DATETIME NOT NULL,
... first_execution_time DATETIME,
... workflow_name VARCHAR(80),
... remaining_executions INTEGER,
... workflow_id VARCHAR(36),
... workflow_input TEXT,
... workflow_input_hash CHAR(64),
... trust_id VARCHAR(80),
... PRIMARY KEY (id),
... UNIQUE (name, project_id),
... UNIQUE (workflow_input_hash, workflow_name, pattern, project_id, remaining_executions, first_execution_time)
... );"""
>>> eng.execute(expr)
<sqlalchemy.engine.result.ResultProxy object at 0x7fb4b83313d0>
>>> expr_insert = """
... INSERT INTO cron_triggers_v2 values (
      '2015-05-25 13:57:01.325866',
       null,
      'private',
      '<default-project>',
      '62e82322-11a9-425b-8872-dfb9fd725dbf',
      'test1',
      '*/5 * * * *',
      '4242-12-25 13:37:00.000000',
      '4242-12-25 13:37:00.000000',
      'my_wf',
       2,
      '29b7707f-23e4-4cfb-895f-effaf88c19de',
      '{}',
      '4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945',
       null
    )"""
>>> eng.execute(expr_insert)
<sqlalchemy.engine.result.ResultProxy object at 0x7fb4b8348610>
>>> expr_insert2 = """
... INSERT INTO cron_triggers_v2 values (
      '2015-05-25 13:57:01.325866',
       null,
      'private',
      '<default-project>',
      '62e82322-11a9-425b-8872-dfb9fd725dbf',
      'test2',
      '*/5 * * * *',
      '4242-12-25 13:37:00.000000',
      '4242-12-25 13:37:00.000000',
      'my_wf',
       2,
      '29b7707f-23e4-4cfb-895f-effaf88c19de',
      '{}',
      '4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945',
       null
    )"""
>>> eng.execute(expr_insert2)
No handlers could be found for logger "oslo_db.sqlalchemy.exc_filters"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1863, in execute
    return connection.execute(statement, *multiparams, **params)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 833, in execute
    return self._execute_text(object, multiparams, params)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 982, in _execute_text
    statement, parameters
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1070, in _execute_context
    context)
  File "oslo_db/sqlalchemy/compat/handle_error.py", line 155, in _handle_dbapi_exception
    e, statement, parameters, cursor, context)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1267, in _handle_dbapi_exception
    util.raise_from_cause(newraise, exc_info)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py", line 1063, in _execute_context
    context)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py", line 442, in do_execute
    cursor.execute(statement, parameters)
oslo_db.exception.DBError: (IntegrityError) UNIQUE constraint failed "\nINSERT INTO cron_triggers_v2 values ('2015-05-25 13:57:01.325866', null, 'private', '<default-project>', '62e82322-11a9-425b-8872-dfb9fd725dbf', 'test', '*/5 * * * *', '4242-12-25 13:37:00.000000', '4242-12-25 13:37:00.000000', 'my_wf', 2, '29b7707f-23e4-4cfb-895f-effaf88c19de', '{}', '4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945', null)" ()

Changed in oslo.db:
status: New → Confirmed
importance: Undecided → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.