query.get() does not support NULL primary key elements

Issue #1135 resolved
Mike Bayer repo owner created an issue

this because it re-uses the mapper._get_clause and just sets bind params. Either the clause needs to be modified/generated on the fly or the "eq" operator in compile() needs to detect "==None". Probably the former here.

Comments (6)

  1. Former user Account Deleted

    (original author: ged) Not sure if this was the meaning of the original ticket, but query.get(None) produces the following traceback instead of returning None:

      File "/home/openhex/lib/python2.4/sqlalchemy/orm/query.py", line 415, in get
        key = self._only_mapper_zero().identity_key_from_primary_key(ident)
      File "/home/openhex/lib/python2.4/sqlalchemy/orm/mapper.py", line 935, in identity_key_from_primary_key
        return (self._identity_class, tuple(util.to_list(primary_key)), self.entity_name)
    TypeError: iteration over non-sequence
    

    This is because util.to_list returns None

  2. Mike Bayer reporter

    get(None) is not a valid use case. we mean primary keys with null elements: get([None](2,)).

  3. Mike Bayer reporter

    the attached patch should be most of the basic idea here. cleans up some nasty cruft in lazyloader too. can consider backporting this to 0.5 as well.

  4. Log in to comment