Re: [sqlalchemy] Re: Strange ObjectDeletedError

2011-02-09 Thread Michael Bayer
sure, you commit too often, and if you're expiring too, then you're 
re-selecting all the time.


On Feb 9, 2011, at 3:54 AM, Romy Maxwell wrote:

> I never did understand the pros or cons of running autocommit=True,
> aside from this flushing issue. Are there performance implications ?
> 
> On Mon, Feb 7, 2011 at 1:22 PM, Michael Bayer  
> wrote:
>> I actually just did a little bit of reverse course on this in 0.7.   I've 
>> moved all the accounting into the try/except block so that the flush 
>> completes fully before the autocommit expires everything.   This is a change 
>> to a pattern that's been the same way since 0.4 so hoping nothing bad 
>> happens when we put 0.7 out into betas.
>> 
>> 
>> On Feb 7, 2011, at 2:52 PM, Romy Maxwell wrote:
>> 
>>> Are there any downsides to setting expire_on_commit=False when using
>>> autocommit=True ? In other words, should I expect to see stale data or
>>> other side effects ?
>>> 
>>> On Mon, Feb 7, 2011 at 8:30 AM, Michael Bayer  
>>> wrote:
 
 On Feb 7, 2011, at 7:42 AM, Romy Maxwell wrote:
 
> Hey Michael,
> 
> I didn't wanna revive a really old thread
> [http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg16598.html],
> so I figured maybe you won't mind the email.
> 
> I don't understand why, in the thread, using autocommit=True makes the
> object unreachable, or what that actually means. I'm assuming it was
> referring to the latter part of the code:
> 
>> o = s.query(T).get(2)
>> o.id = 10
>> o.description = "Changed"
>> s.flush()
> 
> With autocommit=True, I've always thought flushes created their own
> transactions, like so:
> 
> s.begin()
> s.flush()
> s.commit()
> 
> But if that was true, then the commit happens after the flush. How
> would the commit expire anything and/or make anything unreachable for
> the flush ?
 
 
 The commit is expiring because that's what it does when expire_on_commit 
 is True.So the flush goes into its post-commit accounting, it in fact 
 has to reload all the objects, one at a time, so is hugely inefficient and 
 I'm going to add a big warning for that in 0.7, ticket 2041.
 
 
 
>> 
>> 
> 
> -- 
> 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 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: Strange ObjectDeletedError

2011-02-09 Thread Romy Maxwell
I never did understand the pros or cons of running autocommit=True,
aside from this flushing issue. Are there performance implications ?

On Mon, Feb 7, 2011 at 1:22 PM, Michael Bayer  wrote:
> I actually just did a little bit of reverse course on this in 0.7.   I've 
> moved all the accounting into the try/except block so that the flush 
> completes fully before the autocommit expires everything.   This is a change 
> to a pattern that's been the same way since 0.4 so hoping nothing bad happens 
> when we put 0.7 out into betas.
>
>
> On Feb 7, 2011, at 2:52 PM, Romy Maxwell wrote:
>
>> Are there any downsides to setting expire_on_commit=False when using
>> autocommit=True ? In other words, should I expect to see stale data or
>> other side effects ?
>>
>> On Mon, Feb 7, 2011 at 8:30 AM, Michael Bayer  
>> wrote:
>>>
>>> On Feb 7, 2011, at 7:42 AM, Romy Maxwell wrote:
>>>
 Hey Michael,

 I didn't wanna revive a really old thread
 [http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg16598.html],
 so I figured maybe you won't mind the email.

 I don't understand why, in the thread, using autocommit=True makes the
 object unreachable, or what that actually means. I'm assuming it was
 referring to the latter part of the code:

> o = s.query(T).get(2)
> o.id = 10
> o.description = "Changed"
> s.flush()

 With autocommit=True, I've always thought flushes created their own
 transactions, like so:

 s.begin()
 s.flush()
 s.commit()

 But if that was true, then the commit happens after the flush. How
 would the commit expire anything and/or make anything unreachable for
 the flush ?
>>>
>>>
>>> The commit is expiring because that's what it does when expire_on_commit is 
>>> True.    So the flush goes into its post-commit accounting, it in fact has 
>>> to reload all the objects, one at a time, so is hugely inefficient and I'm 
>>> going to add a big warning for that in 0.7, ticket 2041.
>>>
>>>
>>>
>
>

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: Strange ObjectDeletedError

2011-02-07 Thread Michael Bayer
I actually just did a little bit of reverse course on this in 0.7.   I've moved 
all the accounting into the try/except block so that the flush completes fully 
before the autocommit expires everything.   This is a change to a pattern 
that's been the same way since 0.4 so hoping nothing bad happens when we put 
0.7 out into betas.   


On Feb 7, 2011, at 2:52 PM, Romy Maxwell wrote:

> Are there any downsides to setting expire_on_commit=False when using
> autocommit=True ? In other words, should I expect to see stale data or
> other side effects ?
> 
> On Mon, Feb 7, 2011 at 8:30 AM, Michael Bayer  
> wrote:
>> 
>> On Feb 7, 2011, at 7:42 AM, Romy Maxwell wrote:
>> 
>>> Hey Michael,
>>> 
>>> I didn't wanna revive a really old thread
>>> [http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg16598.html],
>>> so I figured maybe you won't mind the email.
>>> 
>>> I don't understand why, in the thread, using autocommit=True makes the
>>> object unreachable, or what that actually means. I'm assuming it was
>>> referring to the latter part of the code:
>>> 
 o = s.query(T).get(2)
 o.id = 10
 o.description = "Changed"
 s.flush()
>>> 
>>> With autocommit=True, I've always thought flushes created their own
>>> transactions, like so:
>>> 
>>> s.begin()
>>> s.flush()
>>> s.commit()
>>> 
>>> But if that was true, then the commit happens after the flush. How
>>> would the commit expire anything and/or make anything unreachable for
>>> the flush ?
>> 
>> 
>> The commit is expiring because that's what it does when expire_on_commit is 
>> True.So the flush goes into its post-commit accounting, it in fact has 
>> to reload all the objects, one at a time, so is hugely inefficient and I'm 
>> going to add a big warning for that in 0.7, ticket 2041.
>> 
>> 
>> 

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: Strange ObjectDeletedError

2009-10-05 Thread Y3s



On Oct 5, 4:59 am, Michael Bayer  wrote:
> On Oct 4, 2009, at 7:54 PM, Y3s wrote:
>
> > Session = orm.sessionmaker(autocommit=True, autoflush=False)
>
> you're using non-default session settings, all attributes are expired  
> upon transaction commit which in this case due to autocommit makes the  
> object unreachable within the flush, so set expire_on_commit=False  
> along with your autocommit=True.
>

Thank you!
--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Strange ObjectDeletedError

2009-10-04 Thread Michael Bayer

On Oct 4, 2009, at 7:54 PM, Y3s wrote:

> Session = orm.sessionmaker(autocommit=True, autoflush=False)

you're using non-default session settings, all attributes are expired  
upon transaction commit which in this case due to autocommit makes the  
object unreachable within the flush, so set expire_on_commit=False  
along with your autocommit=True.


> e = create_engine("sqlite:///")
> m.bind = e
> Session.configure(bind=e)
> m.create_all()
>
> # Insert objects...
> s = Session()
> for x in range(1, 6):
>t = T()
>t.id = x
>t.description = "Object %s" % x
>s.add(t)
> s.flush()
>
> # ...now try to change the ID of one of them...
> o = s.query(T).get(2)
> o.id = 10
> o.description = "Changed"
> s.flush()


--~--~-~--~~~---~--~~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---