committed, r2409.

the "row" needs to have a "class" and "entity_name" present to  
determine what mapper you want to use to extract from the row, so i  
put those as keyword arguments for now.

also, I notice the usage of plain old "assert" for argument  
checking.  should we make this change across the board and get rid of  
exceptions.ArgumentError ?  i feel like we have to go one way or the  
other with that.

also i didnt do any testing of this, we might want to add some tests  
to test/orm/session.py .


On Mar 12, 2007, at 9:21 PM, Daniel Miller wrote:

> def identity_key(self, *args, **kwargs):
>     """Get an identity key
>
>     Valid call signatures:
>
>     identity_key(class_, ident, entity_name=None)
>         class_ - mapped class
>         ident - primary key, if the key is composite this is a tuple
>         entity_name - optional entity name. May be given as a
>             positional arg or as a keyword arg.
>
>     identity_key(instance=instance)
>         instance - object instance (must be given as a keyword arg)
>
>     identity_key(row=row)
>         row - result proxy row (must be given as a keyword arg)
>     """
>     if args:
>         kw = {}
>         if len(args) == 2:
>             class_, ident = args
>             entity_name = kwargs.pop("entity_name", None)
>             assert not kwargs, ("unknown keyword arguments: %s"
>                 % (kwargs.keys(),))
>         else:
>             assert len(args) == 3, ("two or three positional args  
> are "
>                 "accepted, got %s" % len(args))
>             class_, ident, entity_name = args
>         mapper = _class_mapper(class_, entity_name=entity_name)
>         return mapper.instance_key_from_primary_key(ident,
>             entity_name=entity_name)
>     else:
>         try:
>             instance = kwargs.pop("instance")
>         except KeyError:
>             row = kwargs.pop("row")
>             assert not kwargs, ("unknown keyword arguments: %s"
>                 % (kwargs.keys(),))
>             mapper = # not sure how to get the mapper form a row
>             return mapper.identity_key_from_row(row)
>         else:
>             assert not kwargs, ("unknown keyword arguments: %s"
>                 % (kwargs.keys(),))
>             mapper = _object_mapper(instance)
>             return mapper.identity_key_from_instance(instance)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to