Function `_change_deleted_column_type_to_boolean_sqlite()` fails if a table has a foreign constraint

Bug #1210163 reported by Viktor Serhieiev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo-incubator
Fix Released
Undecided
Viktor Serhieiev

Bug Description

Metadata doesn’t contains tables, referenced by foreign keys of the table, being changed.

See traceback

======================================================================
ERROR: tests.unit.db.sqlalchemy.test_utils.TestMigrationUtils.test_change_deleted_column_type_to_boolean_with_fc
----------------------------------------------------------------------
_StringException: Empty attachments:
  pythonlogging:'openstack.common'

Traceback (most recent call last):
  File "/home/vsergeev/sandbox/oslo-incubator/tests/unit/db/sqlalchemy/test_utils.py", line 384, in test_change_deleted_column_type_to_boolean_with_fc
    table_2.create()
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/schema.py", line 593, in create
    checkfirst=checkfirst)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 2302, in _run_visitor
    conn._run_visitor(visitorcallable, element, **kwargs)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1972, in _run_visitor
    **kwargs).traverse_single(element)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/sql/visitors.py", line 106, in traverse_single
    return meth(obj, **kw)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/engine/ddl.py", line 86, in visit_table
    self.connection.execute(schema.CreateTable(table))
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1449, in execute
    params)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1536, in _execute_ddl
    compiled = ddl.compile(dialect=dialect)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/sql/expression.py", line 1778, in compile
    return self._compiler(dialect, bind=bind, **kw)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/schema.py", line 2908, in _compiler
    return dialect.ddl_compiler(dialect, self, **kw)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 705, in __init__
    self.string = self.process(self.statement)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 724, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/sql/visitors.py", line 72, in _compiler_dispatch
    return getter(visitor)(self, **kw)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/sql/compiler.py", line 1612, in visit_create_table
    const = self.create_table_constraints(table)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/sql/compiler.py", line 1632, in create_table_constraints
    for constraint in constraints
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/sql/compiler.py", line 1630, in <genexpr>
    return ", \n\t".join(p for p in
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/sql/compiler.py", line 1638, in <genexpr>
    not getattr(constraint, 'use_alter', False)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 724, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/sql/visitors.py", line 72, in _compiler_dispatch
    return getter(visitor)(self, **kw)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/dialects/sqlite/base.py", line 454, in visit_foreign_key_constraint
    remote_table = list(constraint._elements.values())[0].column.table
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/util/langhelpers.py", line 494, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "/home/vsergeev/sandbox/oslo-incubator/.tox/py26/lib/python2.6/site-packages/sqlalchemy/schema.py", line 1392, in column
    tname)
NoReferencedTableError: Foreign key associated with column 'bcd.foreign_id' could not find table '' with which to generate a foreign key to target column 'None'

-------------------- >> begin captured logging << --------------------
tests.unit.db.sqlalchemy.test_migrations: DEBUG: config_path is /home/vsergeev/sandbox/oslo-incubator/tests/unit/db/sqlalchemy/test_migrations.conf
--------------------- >> end captured logging << ---------------------

Tags: db
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo-incubator (master)

Fix proposed to branch: master
Review: https://review.openstack.org/40878

Changed in oslo:
assignee: nobody → Victor Sergeyev (vsergeyev)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo-incubator (master)

Reviewed: https://review.openstack.org/40878
Committed: http://github.com/openstack/oslo-incubator/commit/56ff3b31d5fcac3bf52ee1e80f5c9c300df2c392
Submitter: Jenkins
Branch: master

commit 56ff3b31d5fcac3bf52ee1e80f5c9c300df2c392
Author: Victor Sergeyev <email address hidden>
Date: Thu Aug 8 11:44:26 2013 +0300

    Use single meta when change column type

    Function _change_deleted_column_type_to_boolean_sqlite() from module
    openstack.common.db.sqlalchemy.utils uses get_table() function to get
    required Table object. Function get_table() creates a MetaData object and
    returns the Table instance using this metadata. When function
    `_change_deleted_column_type_to_boolean_sqlite` creates new table, it
    also create new MetaData() objects.
    It's works fine in most cases, but when table has foreign key, there is
    no possibility to find related table for new table because related table
    absent in new metadata.

    To fix this issue we get metadata from received Table object.
    Test added.

    Fixes bug 1210163

    Change-Id: I9c441d263e6e87fce702b12f5d2c4a9144cfb7e4

Changed in oslo:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in oslo:
milestone: none → havana-3
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in oslo:
milestone: havana-3 → 2013.2
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.