Duplicate table in JOINs when using more than one Proxy attribute in the same class

Bug #664056 reported by Edoardo Serra
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Storm
New
Undecided
Unassigned

Bug Description

Hi, I just came across a bug in storm against the current trunk.
Some unit tests to reproduce it are following.

class Foo(object):
    __storm_table__ = "foo"
    id = Int(primary=True)
    title = Unicode()

class Baz(object):
    __storm_table__ = "baz"
    id = Int(primary=True)
    title = Unicode()

class FooBazProxy(object):
    __storm_table__ = "foobaz"
    id = Int(primary=True)
    foo_id = Int()
    foo = Reference(foo_id, Foo.id)
    foo_title = Proxy(foo, Foo.title)
    baz_id = Int()
    baz = Reference(baz_id, Baz.id)
    baz_title = Proxy(baz, Baz.title)

def test_multi_proxy(self):
    result = self.store.find(FooBazProxy).order_by(Baz.title, Foo.title)
    self.assertEquals(list(result.values(FooBazProxy.id,
        FooBazProxy.foo_title, FooBazProxy.baz_title)),
            [(3, u'Title 10', u'Title 100'),
                (2, u'Title 20', u'Title 100'),
                (1, u'Title 30', u'Title 200')])

This test generates the following query:

SELECT foobaz.id, foo.title, baz.title FROM foobaz LEFT JOIN baz ON foobaz.baz_id = baz.id, foobaz LEFT JOIN foo ON foobaz.foo_id = foo.id ORDER BY baz.title, foo.title

The above query fails on PostgreSQL, MySQL and SQLite with the following error messages:
 * PostgreSQL: ProgrammingError: table name "foobaz" specified more than once
 * MySQL: OperationalError: ambiguous column name: foobaz.id
 * SQLLite: OperationalError: (1066, "Not unique table/alias: 'foobaz'")

I'm working on a patch, hope to get back to you soon.

Regards

Edoardo

Revision history for this message
Edoardo Serra (edoardo-serra) wrote :

Here is my patch, including unit tests.

My 2 cents

Revision history for this message
Edoardo Serra (edoardo-serra) wrote :

Sorry guys, attached the wrong file.
Here is the correct one

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.