The way to hook most parts of the ORM is by creating a MapperExtension
<http://www.sqlalchemy.org/docs/adv_datamapping.html#advdatamapping_exte
nding>. Basically, define a subclass of MapperExtension, overriding
whichever method you are interested in (possibly append_result or
create_instance in your case), and pass an instance of this class as the
'extension' parameter to the mapper.

However, I think it would be worthwhile trying to understand exactly why
the current recipe isn't working for you. (I see someone has updated it
to put the session in the hashkey - I'm not sure I would have been brave
enough to do that until at least one other person had said it was the
right thing to do. I don't really know what I'm talking about ;-) )

If you have any places in your code where you create UniqueName objects
without explicitly saying UniqueName(<whatever>), then they won't pass
through the metaclass __call__ method, and therefore won't get added to
the cache. This also includes situations where the object is loaded from
a relation on another class.

But I don't understand why that would be a problem, as that would only
affect instances that already exist in the database, and because of the
identity_map magic, you will only get one object in the session
representing that row anyway.

I think a testcase is probably needed - you could try and make a single
script that starts two threads and performs operations on UniqueName
obects, and see if you can get the same failure.

Simon

-----Original Message-----
From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED]
On Behalf Of kris
Sent: 18 June 2007 20:48
To: sqlalchemy
Subject: [sqlalchemy] Re: UniqueObject recipe and turbogears


I agree with your summary, I also noted that sqlalchemy doesn't really
like
to have objects that are linked together and in different sessions.

I tried using hash_key = (session.context, name), but this failed in
the same way.
Loading the code with log statement, I note that some object are
loaded
not with the UniqueName loader, but probably by sqlalchemy itself.

I believe it is those objects that are creating the conflict.

Is there a way to hook the sqlalchemy loading system, so I can place
the object
in the cache?





--~--~---------~--~----~------------~-------~--~----~
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