Re: [Sqlalchemy-tickets] [sqlalchemy] #1458: improve quality of error message when attempting to ge
Brought to you by:
zzzeek
From: sqlalchemy <mi...@zz...> - 2009-06-29 15:26:27
|
#1458: improve quality of error message when attempting to get an object from a multi-column-primary-key without sufficient elements --------------------------------+------------------------------------------- Reporter: phrrngtn | Owner: zzzeek Type: enhancement | Status: new Priority: low | Milestone: Component: (none) | Severity: trivial - <10 minutes Resolution: | Keywords: Status_field: awaiting triage | --------------------------------+------------------------------------------- Old description: > sqlalchemy/orm/query.py: > mapper = q._mapper_zero() > params = {} > (_get_clause, _get_params) = mapper._get_clause > > _get_clause = q._adapt_clause(_get_clause, True, False) > q._criterion = _get_clause > > for i, primary_key in enumerate(mapper.primary_key): > try: > params[_get_params[primary_key].key] = ident[i] > except IndexError: > raise sa_exc.InvalidRequestError("Could not find > enough values to formulate primary key for " > - "query.get(); primary key columns are %s" % ', > '.join("'%s'" % c for c in q.mapper.primary_key)) > + "query.get(); primary key columns are %s" % ', > '.join("'%s'" % c for c in mapper.primary_key)) New description: change is obvious from the diff. If one has a table with a multi-column primary key and you attempt to do a session.get(i) (i.e. pass in a scalar) or session.get((i,)) (i.e. pass in a tuple of the wrong length), the exception fails with an AttributeError (our session is instantiated with query_cls=CachingQuery but a similar error occurs in the distributed sqlalchemy) "query.get(); primary key columns are %s" % ', '.join("'%s'" % c for c in q.mapper.primary_key)) AttributeError: 'CachingQuery' object has no attribute 'mapper' -- Ticket URL: <http://www.sqlalchemy.org/trac/ticket/1458#comment:1> sqlalchemy <http://www.sqlalchemy.org/> The Database Toolkit for Python |