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 #1036 (closed defect: worksforme)

Opened 13 years ago

Last modified 12 years ago

Web app returns HTTP 500 error if sqlalchemy is present

Reported by: barryh Owned by: anonymous
Priority: normal Milestone:
Component: TurboGears Version: 0.9a6
Severity: normal Keywords: sqlalchemy 500 quickstart tutorial


I recently encountered an issue with TurboGears 0.9a6 where a sample application created via 'tg-admin quickstart' would consistently return an HTTP 500 error upon attempting to open the default page via a web browser after successfully starting it up. This instance of TurboGears is running on an i386 Debian sid installation.


A sample application is created successfully:

$ tg-admin quickstart
Enter project name: Wiki 20
Enter package name [wiki20]: 
Do you need Identity (usernames/passwords) in this project? [no] 
Selected and implied templates:
  TurboGears#tgbase      tg base template
  TurboGears#turbogears  web framework

  identity:  none
  package:   wiki20
  project:   Wiki-20
Creating template tgbase
Creating directory ./Wiki-20
  Copying start-+package+.py_tmpl to ./Wiki-20/start-wiki20.py
Running /usr/bin/python2.4 setup.py egg_info
Adding TurboGears to paster_plugins.txt
running egg_info
writing requirements to Wiki_20.egg-info/requires.txt
writing Wiki_20.egg-info/PKG-INFO
writing top-level names to Wiki_20.egg-info/top_level.txt
reading manifest file 'Wiki_20.egg-info/SOURCES.txt'
writing manifest file 'Wiki_20.egg-info/SOURCES.txt'

After installation, the application is initialized but returns an HTTP 500 error when opened in a browser. The trace information displayed on the 500 error page is as follows:

500 Internal error

The server encountered an unexpected condition which prevented it from fulfilling the request.

Page handler: <bound method Root.index of <wiki20.controllers.Root object at 0xa73364ac>>
Traceback (most recent call last):
  File "/var/lib/python-support/python2.4/cherrypy/_cphttptools.py", line 105, in _run
  File "/var/lib/python-support/python2.4/cherrypy/_cphttptools.py", line 254, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in index
  File "/var/lib/python-support/python2.4/turbogears/controllers.py", line 273, in expose
    output = database.run_with_transaction(
  File "/var/lib/python-support/python2.4/turbogears/database.py", line 220, in run_with_transaction
AttributeError: 'module' object has no attribute 'objectstore'

Powered by CherryPy? 2.2.1

It occurred to me that I had installed the python-sqlalchemy Debian package (currently at 0.2.5) for some other work, so on a whim I purged it from the system. After purging it, the application started just fine and ran without errors.

It appears that the problematic code is found in <svnco>/turbogears/database.py is the culprit, in lines 11-30 of the 0.9a6 tag:

# Provide support for sqlalchemy
    import sqlalchemy
    from sqlalchemy.ext.proxy import AutoConnectEngine

    # declare the PackageEngine class
    class PackageEngine(AutoConnectEngine):
        An AutoConnectEngine that looks for the dburi based on a package name.
        def __init__(self, package_name, *args, **kwargs):
            def lookup_dburi():
                uri= turbogears.config.get( "%s.sqlalchemy.dburi" % package_name
                                          None )
                return uri or turbogears.config.get( "sqlalchemy.dburi", None )

            AutoConnectEngine.__init__(self, lookup_dburi, *args, **kwargs)

except ImportError:
    sqlalchemy= None

I am not sure whether the issue is the presence of sqlalchemy altogether, or simply that the version currently in the Debian repository is not appropriate for TurboGears to use. Another possibility might be that the absence of a sqlalchemy.dburi setting in dev.cfg is producing an undesirable outcome.

Steps to Reproduce

I can reliably reproduce the issue via the following steps:

1.) Reinstall the python-sqlalchemy package: $ apt-get install python-sqlalchemy

2.) Restart the functioning sample application instance: $ python2.4 start-wiki20.py

3.) Point a browser to  http://localhost:8080/ -- the 500 error appears

4.) Remove the python-sqlalchemy package: $ dpkg -r python-sqlalchemy

5.) Restart the functioning sample application instance: $ python2.4 start-wiki20.py

6.) Point a browser to  http://localhost:8080/ -- the page renders normally

Change History

comment:1 Changed 13 years ago by alberto

  • Status changed from new to closed
  • Resolution set to worksforme

I believe this is a 0.9a6 and SA 0.2.* issue. The problem is that 0.9a6 does not support SA 0.2.* because the latter hasn't got an 'objectstore' attribute (among other changes) hence the exception you're encountering.

Upgrading to TG 0.9a7 (or downgrading SA to 0.1.*) should solve the issue. If this is not the case please feel free to reopen.


Note: See TracTickets for help on using tickets.