Hi there,

We are replacing elixir.session, using a custom context (not thread-
local).  However, doing this does not work.  I'm not sure whether we
understand everything correctly...   Here is some code demonstrating
what we do.  Are we doing anything wrong here?

As given, the code works fine, and creates a row in the DB. But, if
you include the commented line, it seems like the created row is not
committed in the DB.  We're suspecting that the created object is not
part of the correct session.

- Iwan

from sqlalchemy.orm import sessionmaker, scoped_session
import elixir

#elixir.session = scoped_session(sessionmaker(transactional=True),
scopefunc=lambda: 1)
elixir.metadata.bind = 'postgres://rhug:r...@localhost/rhug'

from elixir import Entity, Unicode, Field, using_options

class Thing(Entity):
    using_options(shortnames=True)
    name = Field(Unicode(32), required=True)

elixir.setup_all()
elixir.create_all()


sess = elixir.session()

sess.begin()
aa = Thing(name=u'it')
sess.save(aa)
assert not aa.id

sess.flush()
assert aa.id

sess.commit()
sess.close()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to