I started my demo app using today's TurboGears tarball (rev 663).
Copied in my existing model classes. Put database connections for my
MySQL and SQLObject databases (both identical, created via pure
SQLObject). I comment out one connection or the other depending on
which one I'm testing. In the welcome controller method I put a
sqlobject record as a kid variable:
chem=Chemical.get(2013)
Discovered I needed to put "from MODULE.model import Chemical, hub" in
the controller. welcome.kid has a little paragraph containing two
database fields: ${chem.id} and ${chem.general_desc}. Several
database and config issues came up:
- All four config files exist: dev.cfg, devcfg.py, prod.cfg,
prodcfg.py. But dev.cfg is ignored. I had to put my settings in
devcfg.py. (Symptom: "KeyError: no database configuration found!")
- SQLite works and "mysql:///TABLE" works, but
"notrans_mysql:///TABLE" doesn't. I get "AttributeError: 'NoneType'
object has no attribute 'cache'". The traceback in the browser is
useless (copy at the bottom of this message): it seems to jump
directly from mundane handling to an error handler, with no line
representing the cause of the error. In the TG shell I get the same
error but a much more informative traceback:
$ tg-admin shell
Python 2.4.2 (#1, Jan 6 2006, 12:18:25)
[GCC 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> chem = Chemical.get(2013)
Traceback (most recent call last):
File "<console>", line 1, in ?
File
"/usr/local/lib/python2.4/SQLObject-0.7.1dev_r1534-py2.4.egg/sqlobject/main.py",
line 901, in get
cache = cls._connection.cache
AttributeError: 'NoneType' object has no attribute 'cache'
Now I know it's something to do with the connection. I had to use the
same shell debugging to determine my earlier problems with the ignored
config file and the missing hub import. My tables are MyISAM. Is
there a bug in notrans_mysql: ?
- Is there a way to get cgitb info (the local variables at each
traceback level) in the browser traceback? This makes a serious
difference in terms of debugging ease, as I found with Quixote.
Earlier (a couple months ago) I tried hacking CherryPy for this but it
didn't work.
- My application will be deployed in two environments, one using MySQL
on a web server, the other using SQLite on laptops. I'm not sure if
there will be other configuration differences between the two modes.
If the only difference is the query string, I don't want to maintain
separate configuration files for each mode, I'd rather just use a
short command-line option to select one or the other. The difference
is orthogonical to the dev/prod dichotomy. Should I just do some
magic in the start script to recognize options and update the
configuration, or is there a better way?
- Do I really, really have to put the absolute path in the sqlite:
URL? Right now my project is in Subversion, but since the database is
38 MB I have a symbolic link to it in the project directory. I'd like
to be able to just give the directory to someone else, let him set his
own symlink, and have it just work no matter what the absolute path to
the application or database is. So he doesn't have to update the
configuration every time he updates the directory. Possible?
Here's the uninformative traceback:
Page handler: <bound method Root.index of <cameosd.controllers.Root
object at 0xb73d45ac>>
Traceback (most recent call last):
File
"/usr/local/lib/python2.4/CherryPy-2.2.0beta-py2.4.egg/cherrypy/_cphttptools.py",
line 98, in _run
self.main()
File
"/usr/local/lib/python2.4/CherryPy-2.2.0beta-py2.4.egg/cherrypy/_cphttptools.py",
line 246, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in index
File
"/usr/local/lib/python2.4/TurboGears-0.9a0dev_r663-py2.4.egg/turbogears/controllers.py",
line 184, in expose
func, tg_format, html, fragment, *args, **kw)
File
"/usr/local/lib/python2.4/TurboGears-0.9a0dev_r663-py2.4.egg/turbogears/database.py",
line 193, in run_with_transaction
retval = func(*args, **kw)
File
"/usr/local/lib/python2.4/TurboGears-0.9a0dev_r663-py2.4.egg/turbogears/controllers.py",
line 196, in _execute_func
output = errorhandling.try_call(func, self, *args, **kw)
File
"/usr/local/lib/python2.4/TurboGears-0.9a0dev_r663-py2.4.egg/turbogears/errorhandling.py",
line 64, in try_call
output = dispatch_error(func, self, error, *args, **kw)
File "<string>", line 5, in dispatch_error
File
"/usr/local/lib/python2.4/TurboGears-0.9a0dev_r663-py2.4.egg/turbogears/errorhandling.py",
line 27, in _default_error_handler
return getattr(self, error_source.__name__ )(*args, **kw)
File "<string>", line 3, in index
File
"/usr/local/lib/python2.4/TurboGears-0.9a0dev_r663-py2.4.egg/turbogears/controllers.py",
line 179, in expose
output = _execute_func(self, func, tg_format, html, fragment,
File
"/usr/local/lib/python2.4/TurboGears-0.9a0dev_r663-py2.4.egg/turbogears/controllers.py",
line 196, in _execute_func
output = errorhandling.try_call(func, self, *args, **kw)
File
"/usr/local/lib/python2.4/TurboGears-0.9a0dev_r663-py2.4.egg/turbogears/errorhandling.py",
line 60, in try_call
raise error
AttributeError: 'NoneType' object has no attribute 'cache'
--
Mike Orr <[EMAIL PROTECTED]>
([EMAIL PROTECTED] address is semi-reliable)