On Jan 24, 2008 2:46 PM, Kumar McMillan <[EMAIL PROTECTED]> wrote:
> but, since I am explicitly saving it to a new session and the session
> has a different scope, shouldn't this be possible?  Maybe I'm not
> fully understanding "scoped" sessions.

I am hesitant to file this as a bug because I'm not sure if I
understand scoped sessions correctly.  My understanding is that one
should be able to explicitly attach the same object to different
sessions as long as those sessions have different scopes.

Here are two tests diffed against sqlalchemy trunk.  The first one
passes, as it attaches an unassigned mapped class to multiple sessions
of varying scope.  The second one fails with

InvalidRequestError: Object '[EMAIL PROTECTED]' is already attached
to session '19685424' (this is '19687888')

Should I file a ticket for this?  I looked at the session code briefly
but wasn't sure how to fix it.


Index: test/orm/session.py
===================================================================
--- test/orm/session.py (revision 4097)
+++ test/orm/session.py (working copy)
@@ -962,6 +962,25 @@
         Session.remove()

         assert SomeObject(id=1, data="hello",
options=[SomeOtherObject(someid=1)]) ==
Session.query(SomeObject).one()
+
+    def test_attach_objects_to_multiple_sess(self):
+        Session = scoped_session(sessionmaker())
+        PrivateSession = scoped_session(create_session,
scopefunc=lambda: '__private_session__')
+
+        class SomeObject(fixtures.Base):pass
+        mapper(SomeObject, table)
+
+        so1 = SomeObject()
+        priv_sess = PrivateSession()
+        priv_sess.save(so1)
+        priv_sess.flush()
+
+        so2 = SomeObject()
+        sess = Session()
+        sess.save(so2)
+        sess.flush()
+
+        PrivateSession.remove()


 class ScopedMapperTest(PersistTest):
@@ -1027,6 +1046,21 @@
             pass
         Session.mapper(Baz, table2, extension=ext)
         assert hasattr(Baz, 'query')
+
+    def test_attach_assigned_objects_to_multiple_sess(self):
+        PrivateSession = scoped_session(create_session,
scopefunc=lambda: '__private_session__')
+
+        so1 = SomeObject()
+        priv_sess = PrivateSession()
+        priv_sess.save(so1)
+        priv_sess.flush()
+
+        so2 = SomeObject()
+        sess = Session()
+        sess.save(so2)
+        sess.flush()
+
+        PrivateSession.remove()

     def test_validating_constructor(self):
         s2 = SomeObject(someid=12)

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

Attachment: sa_mapper_scope_tests.diff
Description: Binary data

Reply via email to