Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #870 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

sqlalchemy in database.py is annoying

Reported by: jvanasco@… Owned by: anonymous
Priority: normal Milestone: 1.0b1
Component: TurboGears Version:
Severity: normal Keywords:
Cc:

Description

I don't have a better title sorry.

current sqlalchemy support does this in database.py

objectstore.clear()
do_your_thing()
objectstore.commit()

here's the issue - because of the clear and commit situated where they are, sqlalchemy objects can't persist througout the request - they're locked into whichever cherrypy API stage that you created them in

as an example:

you load session info in before_request_body - ok tg calls the clear/commit you want to write session info in before_finalize based on what happened in the exposed method - failure, because clear/commit happened

suggested approach:

a filter calls a clear() on thread init , and the clear code from database.py become a begin

database.py

             if sqlalchemy:
-                # flush any cached objects
-                sqlalchemy.objectstore.clear()
+               sqlalchemy.objectstore.begin()
            retval = func(*args, **kw)
class SQLalchemyFilter( object ):
    def on_start_resource(self):
        # flush any cached objects
        sqlalchemy.objectstore.clear()
cherrypy.root._cp_filters.append( SQLalchemyFilter() )

Change History

comment:1 Changed 13 years ago by fredlin

does this entry already out of date?

comment:2 Changed 13 years ago by jorge.vargas

  • Status changed from new to closed
  • Version 0.9a6 deleted
  • Resolution set to fixed

that code is long gone.

Note: See TracTickets for help on using tickets.