Hi Sam,

This is expected behavior. If you're using ActiveMapper/assignmapper
(actually anything that uses SessionContextExt), when you create an object,
SA automatically binds it to the current session. You can use session.clearor
session.expunge, as you've discovered. I believe there is also a constructor
argument you can pass to specify the session, you'd so something like
MyClass(..., _sa_bindto=None). However, I couldn't get that working last
time I tried (maybe I just need to check the docs) so I'm using
session.expunge.

Paul


On 6/21/07, SamDonaldson <[EMAIL PROTECTED]> wrote:
>
>
> Hello,
>
> I ran into a complex bug where I found the following:  I wrote a query
> in my model.py where I return a list of tuples that sqlalchemy returns
> to me, and then, to convert those tuples into objects, I wrap my
> sqlalchemy class (representing the table) around the tuple to create a
> list of instances.  I then return that back to the controller action.
> Now note, this was a read from the db of rows that I want to display.
> The problem occurrs when turbogears thinks these are new objects and
> tries to commit them or flush them at the time of returning from the
> controller action.  Why does this happen?  What if I don't want this
> behavior?  This gets fixed if I do session.clear() but I dont 'want to
> have to do that.  I want complete control of when things get commited
> by explicitly calling session.flush() and nothing automatic.
>
> Now that I'm on this topic.  I was wondering - what's the sqlalchemy
> function to convert a list of tuples that have been returned from the
> db back into instances?  If there is one, can it handle the case where
> I select only a few columns and then conver that into an instance?
>
> Thanks,
>
> Sam
>
>
> >
>

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

Reply via email to