cascade in orm relationships shadows ON DELETE CASCADE

Bug #1461102 reported by Salvatore Orlando
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Expired
Medium
Unassigned

Bug Description

In [1] there is a good discussion on how the 'cascade' property specified for sqlachemy.orm.relationship interacts with the 'ON DELETE CASCADE' specified in DDL.

I stumbled on this when I was doing some DB access profiling and noticed multiple DELETE statements were emitted for a delete subnet operation [2], whereas I expected a single DELETE statement only; I expected that the cascade behaviour configured on db tables would have taken care of DNS servers, host routes, etc.

What is happening is that sqlalchemy is perform orm-level cascading rather than relying on the database foreign key cascade options. And it's doing this because we told it to do so. As the SQLAlchemy documentation points out [3] there is no need to add the complexity of orm relationships if foreign keys are correctly configured on the database, and the passive_deletes option should be used.

Enabling such option in place of all the cascade options for relationship caused a single DELETE statement to be issued [4].
This is not a massive issue (possibly the time spent in extra queries is just .5ms), but surely it is something worth doing - if nothing else because it seems Neutron is not using SQLAlchemy in the correct way.

As someone who's been doing this mistake for ages, for what is worth this has been for me a moment where I realized that sometimes it's good to be told RTFM.

[1] http://docs.sqlalchemy.org/en/latest/orm/cascades.html
[2] http://paste.openstack.org/show/256289/
[3] http://docs.sqlalchemy.org/en/latest/orm/collections.html#passive-deletes
[4] http://paste.openstack.org/show/256301/

Tags: db
Changed in neutron:
importance: Undecided → Medium
Changed in neutron:
status: New → Opinion
importance: Medium → Wishlist
milestone: liberty-1 → none
Changed in neutron:
importance: Wishlist → Medium
Revision history for this message
Armando Migliaccio (armando-migliaccio) wrote :

Have you formulated an opinion?

Changed in neutron:
status: Opinion → Incomplete
Revision history for this message
Armando Migliaccio (armando-migliaccio) wrote :

This bug is > 240 days without activity. We are unsetting assignee and milestone and setting status to Incomplete in order to allow its expiry in 60 days.

If the bug is still valid, then update the bug status.

Changed in neutron:
assignee: Salvatore Orlando (salvatore-orlando) → nobody
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for neutron because there has been no activity for 60 days.]

Changed in neutron:
status: Incomplete → Expired
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.