DB: sorting on elements which are AssociationProxy fails
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
neutron |
Fix Released
|
Low
|
pandatt |
Bug Description
If I do a DB query trying to sort by a column which is an AssociationProxy I get the following exception:
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
Nov 20 14:41:20 centos.rdocloud neutron-
This is reproducible for example by querying ports sorted by 'created_at' attribute:
ports = self._plugin.
Looks like we may need to special case the AssociationProxy columns such as we already do in the filtering code at:
Changed in neutron: | |
importance: | Undecided → Low |
status: | New → Confirmed |
tags: | added: db |
Changed in neutron: | |
assignee: | nobody → pandatt (pandatt) |
assignee: | pandatt (pandatt) → nobody |
association proxies represent a link to another table so a simple "order_by()" is not so simple, and is not supported by SQLAlchemy. if we did make it supported, it would involve ordering by a correlated subquery which would be very inefficient in any case.
So I think the check at http:// git.openstack. org/cgit/ openstack/ neutron- lib/tree/ neutron_ lib/db/ utils.py# n45 should be fixed to also reject assocaition proxies, and if you need to ORDER BY the attribute that a proxy refers towards, you should be creating the JOIN that you need and ORDER BY the actual column attribute.