ClassAlias does not generate AS in FROM clause
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Storm |
New
|
Undecided
|
Unassigned |
Bug Description
I have a script that needs to run on Packagings where the product and the sourcepackage each have POTemplates. The POTemplates for the product and the sourcepackage are different. The SQL version looks like this:
SELECT DISTINCT Product.name, ProductSeries.name, SourcePackageNa
FROM POTemplate as UpstreamTemplate, POTemplate, ProductSeries, Product, SourcePackageName, DistroSeries, Packaging
WHERE ProductSeries.
UpstreamTem
POTemplate.
POTemplate.
Packaging.
Packaging.
Packaging.
Crucially, the POTemplate column is listed twice in the FROM clause-- once using AS to make it distinct.
I tried to Stormify the query using ClassAlias:
PackageTemplate = ClassAlias(
return store.find(
)
The result had no AS in the FROM clause:
SELECT Packaging.
FROM DistroSeries, POTemplate, Packaging, ProductSeries, SourcePackageName
WHERE Packaging.
Packaging.
Packaging.
POTemplate.
POTemplate.
POTemplate.
It appears ClassAlias had no effect, and this changes the meaning completely, because while a Product and a sourcepackage may each have POTemplates, they will never have *the same* POTemplate.
I worked around this bug using a sub-select.
There must be something else going on here. I tried to produce a simplified test case and can not reproduce the problem:
>>> from storm.expr import compile, Select Select( [Foo.id] , [Foo.id == Bar.id]))
>>> from storm.info import ClassAlias
>>> from storm.properties import Int
>>> class Foo(object):
... __storm_table__ = 'foo'
... id = Int(primary=True)
...
>>> Bar = ClassAlias(Foo)
>>> compile(
u'SELECT foo.id FROM foo, foo AS "_1" WHERE foo.id = "_1".id'
Are there any other special details about the classes or attributes?