Mapping a class to a table with a pk named as one of the class property fails
(original reporter: ged) It seems like the property overrides the column. Would it be possible (desirable?) to allow for this use case, even if the column is not "renamed" as another property?
The attached test script fails with:
Traceback (most recent call last):
File "test_pk_prop_sa.py", line 21, in <module>
m = mapper(Thing, thing_table)
File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/__init__.py", line 670, in mapper
return Mapper(class_, local_table, *args, **params)
File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/mapper.py", line 197, in __init__
self.__compile_pks()
File "/home/ged/devel/sqlalchemy/trunk/lib/sqlalchemy/orm/mapper.py", line 539, in __compile_pks
raise sa_exc.ArgumentError("Mapper %s could not assemble any primary key columns for mapped table '%s'" % (self, self.mapped_table.description))
sqlalchemy.exc.ArgumentError: Mapper Mapper|Thing|thing could not assemble any primary key columns for mapped table 'thing'
Comments (6)
-
Account Deleted -
repo owner the policy in 0.5 is that end-user descriptors are roughly equivalent to including the column in the "exclude" list. There were some trac tickets that specifically required this policy. So I think elixir is going to have to work around this one.
- Figure out the primary key explicitly:
m = mapper(Thing, thing_table, primary_key=[thing_table.c.name](thing_table.c.name))
. - Remove class descriptors when you first get the class, put them back at the point at which you call add_property()
- add placeholder column_properties for primary key columns that you've observed are being overridden by a descriptor
- the best approach: don't use add_property() (I don't really see why you need to be using add_property() since you work from a deferred compilation step anyway)
- Figure out the primary key explicitly:
-
Hmm, I'm feeling a strong "wontfix" here. Is there anything left to discuss on this one?
-
repo owner - changed milestone to 0.5.xx
I think the
add_property()
call should raise an error if its not going to be honored in the expected manner. -
repo owner - changed status to wontfix
yeah looking at this again its pretty much a "wontfix" - the PK columns have to be stated up front with the mapper. If you knew the PK cols, this makes it work:
m = mapper(Thing, thing_table, primary_key=[thing_table.c.name](thing_table.c.name)) m.add_property('_name', thing_table.c.name)
-
repo owner - removed milestone
Removing milestone: 0.6.xx (automated comment)
- Log in to comment
(original author: ged) Oh, yes, forgot to tell, that this was initially reported on Elixir trac at: http://elixir.ematia.de/trac/ticket/71
The problem is that Elixir adds all properties after the initial mapper creation through add_property.