This fails when added to tests/orm/mapper.py:
       
    def testjoinwithlabels(self):
        class UserWithAddress(object):
            pass
        j = join(users, addresses)
        s = select(use_labels=True, from_obj=[j]).alias('foo')
        m = mapper(UserWithAddress, s)
        q = create_session().query(m)

Traceback (most recent call last):
  File "test/orm/mapper.py", line 265, in testjoinwithlabels
    q = create_session().query(m)
  File "./lib/sqlalchemy\orm\session.py", line 182, in query
    return query.Query(mapper_or_class, self)
  File "./lib/sqlalchemy\orm\query.py", line 19, in __init__
    self.mapper = class_or_mapper.compile()
  File "c:\Documents and Settings\Jonathan Ellis\Desktop\projects\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 158, in compile
    mapper._do_compile()
  File "c:\Documents and Settings\Jonathan Ellis\Desktop\projects\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 191, in _do_compile
    self._compile_tables()
  File "c:\Documents and Settings\Jonathan Ellis\Desktop\projects\sqlalchemy\lib\sqlalchemy\orm\mapper.py", line 327, in _compile_tables
    raise exceptions.ArgumentError("Could not assemble any primary key columns for mapped table %r, tables %r" % ( self.mapped_table.name, self.tables.tables))
ArgumentError: Could not assemble any primary key columns for mapped table 'foo'

I dug into the code a bit and what is happening is that when it gets to this code block

        else:
            # no user-defined primary key columns - go through all of our represented tables
            # and assemble primary key columns
            for t in self.tables + [self.mapped_table ]:
                try:
                    l = self.pks_by_table[t]
                except KeyError:
                    l = self.pks_by_table.setdefault(t, util.OrderedSet())
                for k in t.primary_key:
                    l.add(k)

this adds the PKs from the tables in the join passed to from_obj, but none is ever chosen as "the" PK for pks_by_table[self.mapped_table].

--
Jonathan Ellis
http://spyced.blogspot.com
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to