← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1550027] Re: db.migrations.create_foreign_keys forces new constraints to have ondelete=CASCADE option

 

Reviewed:  https://review.openstack.org/287619
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=5ca8d0152afdd8dd178432c112d1e4ad9bde42ff
Submitter: Jenkins
Branch:    master

commit 5ca8d0152afdd8dd178432c112d1e4ad9bde42ff
Author: Zhengguang <zhengguangou@xxxxxxxxx>
Date:   Thu Mar 3 14:40:01 2016 +0800

    Fixes force to set ondelete=CASCADE in create_foreign_keys()
    
    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.
    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.
    
    Change-Id: I04bdc863d67e2228f34a05f588c2e9f562918114
    Closes-Bug: #1550027


** Changed in: neutron
       Status: In Progress => Fix Released

-- 
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:
  Fix Released

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


References