On 3 Feb 2014 09:51:20 Michael Bayer <mike...@zzzcomputing.com> wrote:
> On Feb 3, 2014, at 2:39 AM, Wolfgang Schnerring <w...@gocept.com> wrote:
> > I guess I didn't make it clear enough that I'm talking mainly about
> > this collections issue. Sorry about that; let me try again:
> > I feel it would be much more convenient if the state achieved by a savepoint
> > was reflected by collection properties (basically like a real commit), but I
> > don't know whether a) that fits sqlalchemy's usage concept and b) there are
> > adverse performance implications.

Sorry about the delay, but here's an example of the behaviour I'm talking about:

from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship
import sqlalchemy.ext.declarative
import sqlalchemy.orm
import unittest

Base = sqlalchemy.ext.declarative.declarative_base()

class Parent(Base):
    __tablename__ = 'parent'
    id = Column(Integer, primary_key=True)

class Child(Base):
    __tablename__ = 'child'
    id = Column(Integer, primary_key=True)
    parent_id = Column(Integer, ForeignKey('parent.id'))
    parent = relationship(Parent, uselist=False, backref='children')

class ExpireTest(unittest.TestCase):
    def setUp(self):
        self.engine = 
sqlalchemy.create_engine('postgresql://localhost/expiretest')
        self.sessionmaker = sqlalchemy.orm.sessionmaker(bind=self.engine)
        Base.metadata.create_all(self.engine)

    def test_children_should_be_removed_from_collection_on_savepoint(self):
        session = self.sessionmaker()
        parent = Parent()
        Child(parent=parent)
        session.add(parent)
        session.commit()

        parent = session.query(Parent).first()
        self.assertEqual(1, len(parent.children))
        session.begin_nested()
        session.delete(parent.children[0])
        self.assertEqual(0, len(parent.children))


My point is, the last assertion fails, which I find both surprising and
inconvenient. ;) I'd be grateful for any insights you have about this.

Wolfgang

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to