Mapper.columns is keyed based on `key` attribute not column name

Issue #2859 resolved
Former user created an issue

I'm not sure if this is an issue with the documentation or the implementation. Basically they don't match.

The Mapper docs say "are keyed based on the attribute name defined in the mapping, not necessarily the key attribute of the Column itself" but I have a case where this doesn't appear to be true.

Using the 2nd EmailAddress class in the hybrid docs (the first would likely give the same result) I end up getting the "email" column keyed as "_email".

inspector = inspect(EmailAddress)
print(dict(inspector.columns))

results in:

{'_email': Column('email', String(), table=<email_address>), 'id': Column('id', Integer(), table=<email_address>, primary_key=True, nullable=False)}

Comments (2)

  1. Former user Account Deleted

    sorry, I think this is a non-issue but I have no idea how to close the ticket...

  2. Mike Bayer repo owner

    the result you're getting is correct, the mapping links those columns to the attribute name specified in declarative first and foremost over that of .name or .key of the Column itself.

  3. Log in to comment