DB: sorting on elements which are AssociationProxy fails

Bug #1804259 reported by Daniel Alvarez
6
This bug affects 1 person
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-server[11934]: ERROR neutron.plugins.ml2.managers File "/opt/stack/neutron/neutron/db/db_base_plugin_v2.py", line 1438, in get_ports
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers page_reverse=page_reverse)
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers File "/opt/stack/neutron/neutron/plugins/ml2/plugin.py", line 1935, in _get_ports_qu
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers *args, **kwargs)
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers File "/opt/stack/neutron/neutron/db/db_base_plugin_v2.py", line 1418, in _get_ports_
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers *args, **kwargs)
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers File "/opt/stack/neutron/neutron/db/_model_query.py", line 159, in get_collection_qu
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers sort_keys = db_utils.get_and_validate_sort_keys(sorts, model)
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers File "/usr/lib/python2.7/site-packages/neutron_lib/db/utils.py", line 45, in get_and
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers if isinstance(sort_key_attr.property,
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers AttributeError: 'AssociationProxy' object has no attribute 'property'
Nov 20 14:41:20 centos.rdocloud neutron-server[11934]: ERROR neutron.plugins.ml2.managers

This is reproducible for example by querying ports sorted by 'created_at' attribute:

ports = self._plugin.get_ports(context, sorts=[('created_at', True)])

Looks like we may need to special case the AssociationProxy columns such as we already do in the filtering code at:

https://github.com/openstack/neutron/blob/0bb6136919a31751242d2efbefedbd8922b6bd0a/neutron/db/_model_query.py#L88

Tags: db
Revision history for this message
Mike Bayer (zzzeek) wrote :

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.

Changed in neutron:
importance: Undecided → Low
status: New → Confirmed
tags: added: db
Revision history for this message
pandatt (pandatt) wrote :

Seems to duplicated with issue: https://bugs.launchpad.net/neutron/+bug/1659175

Changed in neutron:
assignee: nobody → pandatt (pandatt)
assignee: pandatt (pandatt) → nobody
pandatt (pandatt)
Changed in neutron:
assignee: nobody → pandatt (pandatt)
assignee: pandatt (pandatt) → nobody
Revision history for this message
pandatt (pandatt) wrote :
Changed in neutron:
status: Confirmed → Fix Released
assignee: nobody → pandatt (pandatt)
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.