Hi: One of our applications is generating the following error:
NoSuchColumnError: "Could not locate column in row for column 'client.claims.client_id'" Which is rather strange, because that column is aliased with .label() to "AS Client_ID", so of course that row cannot be located. The exception is raised from within ResultMetaData._key_fallback, which has the following comment: # fallback for targeting a ColumnElement to a textual expression # this is a rare use case which only occurs when matching text() # or colummn('name') constructs to ColumnElements, or after a # pickle/unpickle roundtrip But this isn't true for us. It's a fairly standard query generated like: query = ( session.query(tbl.c.client_id.label("Client_ID")) .filter(tbl.c.group_id.in_(group_ids)) ) Digging deeper into the problem, I set a breakpoint inside _key_fallback to poke around in the ResultMetaData object. A few things seemed somewhat odd to me. The first is that self._keymap contained "client_id" (and not "Client_ID"). But we're using postgres, and dialect.case_sensitive is True. Of course, I then looked into how self._keymap was being populated, and managed to get into the cursor's underlying cursor.description attribute. And this contained all lowercase names, which I suppose is how SQLAlchemy got lowercase names. Also, self._keymap was basically this: {0: (None, None, 0), "client_id": (None, None, 0)} I'm not sure if this correct or not. I also managed to get a hold of the underlying result row before it was used to generate a KeyedTuple (actually, the generation of the first KeyedTuple is where the error occurred). row.keys() produced a list of all lowercase aliases, whereas the original aliases (as mentioned above) were mixed-case. The query itself (at this point) was also an AliasedSelect instance, I'm not sure if that has any bearing. To temporarily work around the problem, we set all of the alias names to lowercase. We recently upgraded from SQLAlchemy 0.7.10 to SQLAlchemy 0.8.2. We are using psycopg2 2.4.4 (dt dec mx pq3 ext). We have thousands of SQLAlchemy queries (including many queries that use mixed-case aliases) in our code base and this seems to be the only query that has any problem. I'm not sure whether or not this is a SQLAlchemy issue or a psycopg2 issue or what, but I figured I'd start here because the error is originating from SQLAlchemy. -Ryan Kelly -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.