Hi,

You need to set the _connection attribute for each model object, so there are two solutions as I know:

1. Add code like this to each module include model object, sqlobject will do it automatically:

from turbogears.database import PackageHub
hub = PackageHub("somepackage")
__connection__ = hub

2. If you don't want to modify the imported module, then set it manually for each imported object in model.py :

MyModel._connection = __connection__

It works, but seems not as easy as it should be.
I also want to know if there are any better solution.

On 5/19/06, percious <[EMAIL PROTECTED]> wrote:

For my own set of very good reasons, I want to have all of my
SQLObjects in a separate file for some other processes that I do away
from TG.  I attempted to do this by importing my module to Models.py
with the following line of code:

from ft8.turboLink.help.HelpDatabaseModel import *

Catwalk can read the fact that there are tables in the SQL database
corresponding to the objects, but it cannot read the values in the
table.  Instead, it spits out the following error:

2006-05-18 13:27:56,956 turbogears.identity INFO Identity is
available...
2006-05-18 13:27:56,971 cherrypy.msg INFO HTTP: Page handler: <bound
method Brow
se.index of <turbogears.toolbox.catwalk.browse.Browse object at
0x012F3AD0>>
Traceback (most recent call last):
  File
"c:\python24\lib\site-packages\cherrypy-2.2.1-py2.4.egg\cherrypy\_cphttpt
ools.py", line 105, in _run
    self.main()
  File
"c:\python24\lib\site-packages\cherrypy-2.2.1-py2.4.egg\cherrypy\_cphttpt
ools.py", line 254, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in index
  File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\cont
rollers.py", line 273, in expose
    output = database.run_with_transaction(
  File
"c:\python24\lib\site-packages\TurboGears- 0.9a6-py2.4.egg\turbogears\data
base.py", line 221, in run_with_transaction
    retval = func(*args, **kw)
  File "<string>", line 5, in _expose
  File
"c:\python24\lib\site-packages\TurboGears- 0.9a6-py2.4.egg\turbogears\cont
rollers.py", line 290, in <lambda>
    mapping, fragment, *args, **kw)))
  File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\cont
rollers.py ", line 314, in _execute_func
    output = errorhandling.try_call(func, *args, **kw)
  File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\erro
rhandling.py", line 71, in try_call
    return func(self, *args, **kw)
  File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\tool
box\catwalk\browse.py", line 24, in index
    total,rows =
self.rows_for_model (object_name,start,page_size,filters)
  File
"c:\python24\lib\site-packages\TurboGears-0.9a6-py2.4.egg\turbogears\tool
box\catwalk\browse.py", line 115, in rows_for_model
    total = query.count()
  File
"c:\python24\lib\site-packages\sqlobject-0.7.1dev_r1588-py2.4.egg\sqlobje
ct\sresults.py", line 188, in count
    count = self.accumulate('COUNT(*)')
  File
"c:\python24\lib\site-packages\sqlobject- 0.7.1dev_r1588-py2.4.egg\sqlobje
ct\sresults.py", line 171, in accumulate
    conn = self._getConnection()
  File
"c:\python24\lib\site-packages\sqlobject-0.7.1dev_r1588-py2.4.egg\sqlobje
ct\sresults.py", line 38, in _getConnection
    return self.ops.get('connection') or self.sourceClass._connection
  File
"c:\python24\lib\site-packages\sqlobject-0.7.1dev_r1588-py2.4.egg\sqlobje
ct\dbconnection.py", line 881, in __get__
    return self.getConnection()
  File
"c:\python24\lib\site-packages\sqlobject-0.7.1dev_r1588-py2.4.egg\sqlobje
ct\dbconnection.py", line 893, in getConnection
    raise AttributeError(
AttributeError: No connection has been defined for this thread or
process
Request Headers:
  COOKIE: tg-visit=28a0c3d3b8caa54d4db95cae37f7cd36972f4c66
  Content-Length:
  ACCEPT-CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  USER-AGENT: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.0.3) Gecko/
20060426 Firefox/1.5.0.3
  CONNECTION: keep-alive
  HOST: localhost:8081
  ACCEPT:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 ,text/pl
ain;q=0.8,image/png,*/*;q=0.5
  Remote-Addr: 127.0.0.1
  ACCEPT-LANGUAGE: en-us,en;q=0.5
  Content-Type:
  Remote-Host: 127.0.0.1
  ACCEPT-ENCODING: gzip,deflate
  KEEP-ALIVE: 300
127.0.0.1 - - "GET /catwalk/browse/?object_name=CitectServer HTTP/1.1"
500 3356
"" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: 1.8.0.3)
Gecko/20060426 F
irefox/1.5.0.3"

If I copy and paste my objects into Model.py I get my desired results,
but we all know what kind of drudgery copy and paste can get us into.

Anyone have any ideas?

-chris




--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to