Configurable life time of session bug #5

Closed
fangpenlin opened this Issue Jan 2, 2014 · 0 comments

Projects

None yet

1 participant

@fangpenlin
Contributor

A simple script to reproduce

import transaction
from sqlalchemy import create_engine
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from zope.sqlalchemy import ZopeTransactionExtension

engine = create_engine('sqlite:///')

session = scoped_session(sessionmaker(
    autocommit=False,
    autoflush=False,
    bind=engine,
    extension=ZopeTransactionExtension(keep_session=True)
))

Base = declarative_base()


class Foobar(Base):
    __tablename__ = 'foobar'

    id = Column(Integer, primary_key=True)
    name = Column(String)

Base.metadata.bind = engine
Base.metadata.create_all()


with transaction.manager:
    foobar = Foobar(id=1, name='john')
    session.add(foobar)

foobar = session.query(Foobar).get(1)

with transaction.manager:
    foobar.name = 'jackson'
    session.flush()

# boom! sqlalchemy.orm.exc.DetachedInstanceError will be raised
print foobar.name

After looking into the code, this is caused by join_transaction in mark_changed method doesn't take keep_session and pass along properly.

@fangpenlin fangpenlin added a commit to fangpenlin/zope.sqlalchemy that referenced this issue Jan 2, 2014
@fangpenlin fangpenlin Add #5 test for keep_session bug c9b24cb
@lrowe lrowe pushed a commit that closed this issue Jan 2, 2014
@fangpenlin fangpenlin Fix #5, `keep_session=True` doesn't work when a transaction is joined…
… by flush

  and other manngers bug
628e09a
@lrowe lrowe closed this in 628e09a Jan 2, 2014
@pyup-bot pyup-bot referenced this issue in nicfit/MishMash Feb 26, 2017
Merged

Pin zope.sqlalchemy to latest version 0.7.7 #42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment