I found the cause it this problem. It is not a bug in web2py but
something to be careful about in your programs.

You have a models/meteo.py which imports modules/meteo.py.

models/meteo.py does

   current.database = db

and modules/mete.py does

   db = current.database

the problem is that the latter statement is done at top leve therefor
it is only executed once when the module is imported by the first http
request. The module is then cached in ram and that line is no longer
executed. Therefore db is not the current thread local database
object but it is a reference to the db object of the first http
request which by now may be closed. You cannot extract objects from
the thread local "current" when you import the module, you have to do
it inside functions called when a controller is executed.

Hope this makes sense.



On Jun 24, 10:31 am, Manuele Pesenti <manuele.pese...@gmail.com>
wrote:
> dear all,
> I've added a unique field to some existing tables and w2p gave me an
> error saing that he cannot add unique fields to a table so I deleted my
> db and restarted as a new application but I obtained this:
>
> ProgrammingError: Cannot operate on a closed database.
>
> it's sufficient to comment out the property unique=True and no errors
> occurs.
>
> Here under you can find the complete traceback.
> Any suggestion??
>
> Thanks a lot
>
>         Manuele
>
> Traceback (most recent call last):
>    File
> "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/restricted.py", line
> 192, in restricted
>      exec ccode in environment
>    File
> "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/applications/wind2pow2/contro 
> llers/appadmin.py",
> line 410, in <module>
>    File "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/globals.py",
> line 137, in <lambda>
>      self._caller = lambda f: f()
>    File
> "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/applications/wind2pow2/contro 
> llers/appadmin.py",
> line 126, in insert
>      form = SQLFORM(db[table], ignore_rw=ignore_rw)
>    File "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/sqlhtml.py",
> line 817, in __init__
>      inp = self.widgets.options.widget(field, default)
>    File "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/sqlhtml.py",
> line 206, in widget
>      options = requires[0].options()
>    File
> "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/validators.py", line
> 438, in options
>      self.build_set()
>    File
> "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/validators.py", line
> 426, in build_set
>      records = self.dbset.select(*fields, **dd)
>    File "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/dal.py",
> line 5382, in select
>      return self.db._adapter.select(self.query,fields,attributes)
>    File "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/dal.py",
> line 1159, in select
>      rows = response(sql)
>    File "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/dal.py",
> line 1149, in response
>      self.execute(sql)
>    File "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/dal.py",
> line 1234, in execute
>      return self.log_execute(*a, **b)
>    File "/home/manuele/Dropbox/sviluppo/web2py-1.96.4/gluon/dal.py",
> line 1229, in log_execute
>      ret = self.cursor.execute(*a,**b)
> ProgrammingError: Cannot operate on a closed database.

Reply via email to