Retrieving new instance by identity key?

25 views
Skip to first unread message

Torsten Landschoff

unread,
Jun 18, 2010, 11:05:41 AM6/18/10
to sqlal...@googlegroups.com
Hi *,

I wonder if it is possible and supported in SQLAlchemy to query an
instance by identity key.

Use case: I want a length operation to run in an extra process. That
means I will need an extra database connection in that process and have
to retrieve the objects I am working with again.

To implement this in a generic way, I want to ask sqlalchemy about the
identity key of the instance (using sqlalchemy.orm.util.identity_key).

Using that key, I can retrieve the instance again in the new process.
But where is the method that can do that? I was expecting something like

session.get_instance_by_key(key)

to be in the API, but I am unable to find it.

Any hints?

Greetings, Torsten

--
DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH
Torsten Landschoff

Office Dresden
Tel: +49-(0)351-4519587
Fax: +49-(0)351-4519561

mailto:torsten.l...@dynamore.de
http://www.dynamore.de

Registration court: Mannheim, HRB: 109659, based in Karlsruhe,
Managing director: Prof. Dr. K. Schweizerhof, Dipl.-Math. U. Franz

Torsten Landschoff

unread,
Jun 18, 2010, 11:16:20 AM6/18/10
to sqlal...@googlegroups.com
On Fri, 2010-06-18 at 17:05 +0200, Torsten Landschoff wrote:

> Using that key, I can retrieve the instance again in the new process.
> But where is the method that can do that? I was expecting something like
>
> session.get_instance_by_key(key)
>
> to be in the API, but I am unable to find it.

Looking further, I found Query.key() but its arguments seem to be
incompatible with the result of util.identity_key. In fact, it
translates its input to match the latter and calls Query._get().

What am I missing?

Michael Bayer

unread,
Jun 18, 2010, 11:32:29 AM6/18/10
to sqlal...@googlegroups.com

On Jun 18, 2010, at 11:05 AM, Torsten Landschoff wrote:

> Hi *,
>
> I wonder if it is possible and supported in SQLAlchemy to query an
> instance by identity key.
>
> Use case: I want a length operation to run in an extra process. That
> means I will need an extra database connection in that process and have
> to retrieve the objects I am working with again.
>
> To implement this in a generic way, I want to ask sqlalchemy about the
> identity key of the instance (using sqlalchemy.orm.util.identity_key).
>
> Using that key, I can retrieve the instance again in the new process.
> But where is the method that can do that? I was expecting something like
>
> session.get_instance_by_key(key)
>
> to be in the API, but I am unable to find it.
>
> Any hints?

technically query._get() does this, but in a public sense, for the moment, you'd say

session.query(key[0]).get(key[1])

I say for the moment since the above makes some assumptions about the format of the key itself, which is less than ideal. We haven't built comprehensive patterns out based on identity keys, those util methods are currently the product of one particular user who really wanted to work that way.


>
> Greetings, Torsten
>
> --
> DYNAmore Gesellschaft fuer Ingenieurdienstleistungen mbH
> Torsten Landschoff
>
> Office Dresden
> Tel: +49-(0)351-4519587
> Fax: +49-(0)351-4519561
>
> mailto:torsten.l...@dynamore.de
> http://www.dynamore.de
>
> Registration court: Mannheim, HRB: 109659, based in Karlsruhe,
> Managing director: Prof. Dr. K. Schweizerhof, Dipl.-Math. U. Franz
>

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

Torsten Landschoff

unread,
Jun 19, 2010, 11:40:16 AM6/19/10
to sqlal...@googlegroups.com
Hi Michael,

On Fri, 2010-06-18 at 11:32 -0400, Michael Bayer wrote:

> > session.get_instance_by_key(key)
> >
> > to be in the API, but I am unable to find it.
> >
> > Any hints?
>
> technically query._get() does this, but in a public sense, for the moment, you'd say
>
> session.query(key[0]).get(key[1])
>
> I say for the moment since the above makes some assumptions about the format of the key itself, which is less than ideal. We haven't built comprehensive patterns out based on identity keys, those util methods are currently the product of one particular user who really wanted to work that way.

Thanks for your fast reply. I guess I'll go that route than for now. :)

Reply all
Reply to author
Forward
0 new messages