yahoo-eng-team team mailing list archive
-
yahoo-eng-team team
-
Mailing list archive
-
Message #46943
[Bug 1550027] [NEW] db.migrations.create_foreign_keys forces new constraints to have ondelete=CASCADE option
Public bug reported:
In neutron/db/migration/__init__.py, on line 168, the
create_foreign_keys method there forces any foreign keys that created to
have ondelete='CASCADE', no matter whether the foreign_keys parameter
passed to the method had that option set. This is particularly bad,
because if the wrapper method remove_fks_from_table() is used to
preserve the state of foreign keys during a database migration, any
foreign keys on the table "perserved" this way will have cascading
delete added to them.
The code in create_foreign_keys should look something more like this:
def create_foreign_keys(table, foreign_keys):
for fk in foreign_keys:
ondelete = None
if 'ondelete' in fk['options'].keys():
ondelete = fk['options']['ondelete']
op.create_foreign_key(
constraint_name=fk['name'],
source_table=table,
referent_table=fk['referred_table'],
local_cols=fk['constrained_columns'],
remote_cols=fk['referred_columns'],
ondelete=ondelete
)
** Affects: neutron
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1550027
Title:
db.migrations.create_foreign_keys forces new constraints to have
ondelete=CASCADE option
Status in neutron:
New
Bug description:
In neutron/db/migration/__init__.py, on line 168, the
create_foreign_keys method there forces any foreign keys that created
to have ondelete='CASCADE', no matter whether the foreign_keys
parameter passed to the method had that option set. This is
particularly bad, because if the wrapper method
remove_fks_from_table() is used to preserve the state of foreign keys
during a database migration, any foreign keys on the table "perserved"
this way will have cascading delete added to them.
The code in create_foreign_keys should look something more like this:
def create_foreign_keys(table, foreign_keys):
for fk in foreign_keys:
ondelete = None
if 'ondelete' in fk['options'].keys():
ondelete = fk['options']['ondelete']
op.create_foreign_key(
constraint_name=fk['name'],
source_table=table,
referent_table=fk['referred_table'],
local_cols=fk['constrained_columns'],
remote_cols=fk['referred_columns'],
ondelete=ondelete
)
To manage notifications about this bug go to:
https://bugs.launchpad.net/neutron/+bug/1550027/+subscriptions
Follow ups