mapping arbitrary selectable does not use primary_key argument

Issue #1542 resolved
Former user created an issue

If a selectable does not contain a column that is primary key in a base table, then cannot use that selectable in a mapper.

This code

t2 = Table('t2', meta, Column('bar', Integer))
s2 = select([t2.c.bar](t2.c.bar))
class Two(object): pass
mapper(Two, s2, primary_key=[s2.c.bar](s2.c.bar))  # same error using [t2.c.bar](t2.c.bar)

raises exception

argumentError : Mapper Mapper|Two|%(31476816 anon)s could not assemble any primary key columns for mapped table '%(31476816 anon)s'

When 'bar' is a primary key for table 't2', the mapper is successful.

Comments (2)

  1. Mike Bayer repo owner

    You missed a warning which states:

       util.warn("mapper %s creating an alias for the given "
                            "selectable.  References to the original selectable "
                            "may be misinterpreted by queries, polymorphic_on, etc. "
                            " Consider passing an explicit selectable.alias() construct instead." % self)
    

    the only rationale for the alias() is that databases like PG and MySQL require it. so removed the ambiguity here by raising the warning to an error in cf6c66e70ea406a27c4a8d5b79f9c629a62320fc.

  2. Log in to comment