Package: python-turbogears
Version: 1.0-1
Severity: important
After executing a controller method to handle a page request, TurboGears
is supposed to commit any changes that the controller made to the
database. When using SQLAlchemy, it fails to do this. It's possible to
work around this by modifying the controller to do the commit manually,
but that's not something that the application should be doing. I'm
calling this bug "important" because existing TurboGears-based web
applications, as-written, will not work correctly on this release of
TurboGears if they use SQLAlchemy.
TurboGears' database support (for both SQLObject and SQLAlchemy) is
implemented in the file "turbogears/database.py". This file contains a
generic "run_with_transaction" function:
[dispatch.generic(MultiorderGenericFunction)]
def run_with_transaction(func, *args, **kw):
pass
which is supposed to call either so_rwt() or sa_rwt() depending on
whether SQLObject or SQLAlchemy is in use:
[run_with_transaction.when("not _use_sa()")]
def so_rwt(func, *args, **kw):
...
[run_with_transaction.when("_use_sa()")]
def sa_rwt(func, *args, **kw):
...
The check for whether SQLAlchemy is in use is done by looking at a
global variable:
def _use_sa():
return _engine is not None
The _engine variable is initialized to None near the top of this file,
and a function called get_engine() is provided which may assign an
object to it after reading some options from a config file.
The problem is that the so_rwt() and sa_rwt() functions get registered
with the run_with_transaction() dispatcher at the same time as they're
defined: while Python is executing turbogears/database.py in response
to an import declaration. At this point the get_engine() function has
been defined, but hasn't been run yet, so _engine is always going to be
None, and run_with_transaction() always ends up calling so_rwt(), never
sa_rwt().
How to reproduce this: use quickstart to create a new SQLAlchemy
project, and then run "tg-admin shell" on it. Do the following:
import turbogears.database
turbogears.database.run_with_transaction(None)
This will cause a TypeError exception, and you'll see so_rwt() in the
stack trace.
If I modify turbogears/database.py and put "print _use_sa()" just before
the definition of the so_rwt() function, I see False printed when I
start a shell, even though running turbogears.database._use_sa() from
within the shell yields True. That False is what causes so_rwt() to
become the function that the dispatcher uses, rather than sa_rwt() like
it should.
-- System Information:
Debian Release: 4.0
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable'), (1,
'experimental')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-3-686-bigmem
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Versions of packages python-turbogears depends on:
ii python2.4.4-2An interactive high-level object-o
ii python-celementtree 1.0.5-8Light-weight toolkit for XML proce
ii python-cheetah2.0~rc7-1 text-based template engine and Pyt
ii python-cherrypy 2.2.1-3Python web development framework
ii python-configobj 4.3.2-2a simple but powerful config file
ii python-dispatch 0.5adev-5 Rule-based Dispatching and Generic
ii python-elementtree1.2.6-10 Light-weight toolkit for XML proce
ii python-formencode 0.6-1 validation and form generation pyt
ii python-kid0.9.4-1simple Pythonic template language
ii python-nose 0.9.0-2test discovery and running for Pyt
ii python-paste 1.0.1-1Tools for using a Web Server Gatew
ii python-pastedeploy1.0-1 Load, configure, and compose WSGI
ii python-pastescript1.0-1 serving web applications, creating
ii python-setuptools 0.6c5-2Python Distutils Enhancements
ii python-simplejson 1.5-1 Simple, fast, extensible JSON enco
ii python-sqlalchemy 0.3.1-2SQL toolkit and Object Relational
ii python-sqlobject 0.7.2-1python module for SQLObject
ii python-support0.5.6 automated rebuilding support for p
ii python-turbojson 0.9.5-1TurboGears template plugin that su
ii python-turbokid 0.9.9-1TurboGears template plugin that su
Versions of packages python-turbogears recommends:
ii python-pysqlite2 2.3.2-1python interface to SQLite 3
-- no debconf information
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]