On Wed, Apr 27, 2011 at 5:11 AM, Diez B. Roggisch <[email protected]> wrote:

> On Wednesday, April 27, 2011 04:50:46 am Michael Pedersen wrote:
> > Going by my own experiences, I think it's just a case of your being lucky
> > in your development environment. Quite likely, the timing of the redirect
> > coming to the browser is just long enough for the data to be saved to
> > disk, and the subsequent request from the browser is able to be
> satisfied.
>
> That makes no sense. There is no concurrency involved here. Whatever the
> first
> request does, when the page is returned to the browser, the transaction is
> committed (or rolled back of course), and the data is in the DB. There is
> no
> chance for it to appear later somehow.
>

I have seen the behavior I described occur. It may not make sense, but it
happens. For whatever reasons, the redirect results in a case where the
browser is capable of sending a request for the newly made data before the
data is committed to disk, and the result is an inability for the browser to
get the data.

One way it could make sense: redirect is implemented by way of an exception,
if memory serves. Exceptions result in the normal flow departing, which
would result in the browser getting the redirect before the commit is done
by TG. I haven't looked at the code to verify that is what happens, but that
is a real possibility.


> And DBSession.flush() is the right thing to do, if you want all outstanding
> SQL
> to go to the DB, and thus getting your entities some nice & fresh IDs.
> Commit
> isn't needed for that.
>

Again, I have seen that behavior required, particularly if you are using a
transaction aware database. Since each transaction is executed in isolation,
and therefore not visible outside the transaction, until the actual
commit(), no subsequent request will be able to see those IDs. While this
won't affect (for instance) MySQL, it can affect SQLite, PostgreSQL, and
others.

If all you are looking for is the ID numbers, then yes, flush() is correct.
If you are looking to make sure that other requests can *see* those ID
numbers, then yes, commit() is required.

I may be wrong about the why behind pieces of that, but I am reporting
behavior that I have seen.

-- 
Michael J. Pedersen
My IM IDs: Jabber/[email protected], ICQ/103345809, AIM/pedermj022171
          Yahoo/pedermj2002, MSN/[email protected]
My LinkedIn Profile: http://www.linkedin.com/in/michaeljpedersen

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en.

Reply via email to