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
> 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?
> 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.
>
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. :)