Missing FROM-clause when iterating over a difference ResultSet
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Storm |
New
|
Undecided
|
Unassigned |
Bug Description
Here's a demo:
{{{
>>> from storm.store import Store
>>> cprov = getUtility(
>>> store = Store.of(cprov)
>>> from lp.registry.
>>> all_people = store.find(Person)
>>> all_people.count()
93
>>> cprov_resultset = store.find(Person, Person.name == 'cprov')
>>> cprov_resultset
1
>>> diff = all_people.
>>> diff.count()
92
>>> count = 0
>>> for person in diff:
... count += 1
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/home/
File "/home/
File "/home/
File "/home/
File "/home/
File "/home/
psycopg2.
LINE 1: ..., Person.name))) AS "_2" ORDER BY person_
}}}
Thanks to therve for the workaround: do diff._order_by = Undef before the iteration and all is fine.
So there are two things in play here:
1. The table class in question has a default ordering set using an SQL() constant expression that references columns in "table.column" form.
2. When using the SQLObject compatibility layer, the set expression methods on SQLObjectResultSet default to no ordering on the new result set, even if the table has a default order.
When moving to the native storm ResultSet APIs, the default order set on the table is used for the new result set and we get breakage because "Person" is not bound to anything at that level.
As the code in question is using SQL() here, there isn't much chance of us doing something smart here. That said, I don't think we would handle this any better if the default order was a simple list of column objects. Are there any cases where we successfully apply an order to set expressions?