With a class with 3 primary key columns, e.g. class MyClass(Entity): a = Field(Unicode(64), primary_key=True) b = Field(Unicode(64), primary_key=True) c = Field(Unicode(64), primary_key=True) ...
If you pass 4 values to query.get; MyClass.get(('a_val', 'b_val', 'c_val', 'd_val')) it silently ignores 'd_val' and constructs a query with just a, b and c columns. I don't think this behaviour is desirable! It currently throws an exception if a 2-tuple is passed to it. Fix against trunk attached. In my case I had inadvertently masked the 'd' column: class MyClass(Entity): a = Field(Unicode(64), primary_key=True) b = Field(Unicode(64), primary_key=True) c = Field(Unicode(64), primary_key=True) d = Field(Unicode(64), primary_key=True) ... d = Field(Unicode(64)) So that MyClass.table.primary_key.columns only had a, b and c. Having the MyClass.get only accepting 3-tuples would have caught this error. Side issue - this example uses elixir - should elixir have caught the redeclaration of 'd'? Cheers! Eoghan diff -r 0d9a1a57caac lib/sqlalchemy/orm/query.py --- a/lib/sqlalchemy/orm/query.py Thu Nov 18 20:12:24 2010 -0500 +++ b/lib/sqlalchemy/orm/query.py Fri Nov 19 18:04:59 2010 +0000 @@ -1919,6 +1919,12 @@ q = self._clone() if ident is not None: + if len(ident) != len(mapper.primary_key): + raise sa_exc.InvalidRequestError( + "Incorrect number of values in identifier to formulate " + "primary key for query.get(); primary key columns are %s" % + ','.join("'%s'" % c for c in mapper.primary_key)) + (_get_clause, _get_params) = mapper._get_clause # None present in ident - turn those comparisons @@ -1939,12 +1945,6 @@ for id_val, primary_key in zip(ident, mapper.primary_key) ]) - if len(params) != len(mapper.primary_key): - raise sa_exc.InvalidRequestError( - "Incorrect number of values in identifier to formulate " - "primary key for query.get(); primary key columns are %s" % - ','.join("'%s'" % c for c in mapper.primary_key)) - q._params = params if lockmode is not None: -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.