Re: [web2py] Re: Lazy_tables with virtual fields
Hello, Could it be something related to Dropbox's sync mechanism? Have you tried running your app in another folder outside of Dropbox's reach? Would probably explain why your example works fine on other user's machines. Best regards, JS On Saturday, September 1, 2012 6:34:39 AM UTC+1, Paolo wrote: Hi Massimo, the error is: Cannot operate on a closed database. ticket: Traceback (most recent call last): File /home/paolo/Dropbox/git/pp/web2py/gluon/restricted.py, line 209, in restricted exec ccode in environment File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/views/default/test.html, line 3, in module {{pass}} File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8825, in __call__ return self.method(self.row,*args,**kwargs) File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/models/db.py, line 129, in lambda db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8690, in count return db._adapter.count(self.query,distinct) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1597, in count self.execute(self._count(query, distinct)) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1653, in execute return self.log_execute(*a, **b) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1647, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: Cannot operate on a closed database. I put the code of the simple app in a new app with the latest web2py, the first time I accessed the page all worked well but when I reloaded it, I got the error. Hope this can help you. Best, Paolo 2012/8/31 Massimo Di Pierro massimo@gmail.com javascript:: What's the error? Works for me. On Friday, 31 August 2012 16:00:24 UTC-5, Paolo wrote: Hi Massimo, I made a simple app, accordingly this example the error seems related to the cache, because without the cache all works fine. The model: db.define_table('reviews_like_s', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews_s', Field('title')) db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) db.reviews_s.neg = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == False)).count() ) Function: def test(): id = db.reviews_s.insert(title='xxx') db.reviews_like_s.insert(review_id=id, helpful=True) rows = db(db.reviews_s.id 0).select( cache=(cache.ram,3600) ) return dict(reviews=rows) The view: {{for review in reviews:}} p{{=review.pos()}}/p {{pass}} On my side the first time works well, the second rises the error. Best, Paolo 2012/8/30 paolo@gmail.com paolo@gmail.com: Hi Massimo, no, I do not have multiple models, I have defined the string connection only once in db.py, that's all. I have a few try...except but in other places, I do not thing they are connected. I will try to make a simple app ables to reproduce the problem as soon as possible. Paolo 2012/8/30 Massimo Di Pierro massimo@gmail.com: Can you make a simple app to reproduce this? Do you have try except anywhere? Do you have multiple models wich define the same db = DAL(...) connection? On Thursday, 30 August 2012 15:49:01 UTC-5, Paolo wrote: Hi Bruno, a simple db with sqlite without modules db = DAL('sqlite://storage.sqlite', lazy_tables=True ) sorry, but I've just discovered that the same problem is happened even with lazy_tables=False Paolo 2012/8/30 Bruno Rocha rocha...@gmail.com: How are you defining the db connection? are you using models or modules? which db? -- -- Paolo -- -- Paolo -- Paolo -- -- Paolo --
Re: [web2py] Re: Lazy_tables with virtual fields
I do not fully understand this. It mush have something to do with the scoping of variables in python. Can you try replace db.reviews.pos = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) with db.reviews.pos = Field.Lazy(lambda row,db=db: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row,db=db: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) or with def lazy1(row,db=db): return db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() def lazy2(row,db=db): return db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() db.reviews.pos = Field.Lazy(lazy1) db.reviews.neg = Field.Lazy(lazy2) On Saturday, 1 September 2012 05:50:35 UTC-5, João Saraiva wrote: Hello, Could it be something related to Dropbox's sync mechanism? Have you tried running your app in another folder outside of Dropbox's reach? Would probably explain why your example works fine on other user's machines. Best regards, JS On Saturday, September 1, 2012 6:34:39 AM UTC+1, Paolo wrote: Hi Massimo, the error is: Cannot operate on a closed database. ticket: Traceback (most recent call last): File /home/paolo/Dropbox/git/pp/web2py/gluon/restricted.py, line 209, in restricted exec ccode in environment File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/views/default/test.html, line 3, in module {{pass}} File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8825, in __call__ return self.method(self.row,*args,**kwargs) File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/models/db.py, line 129, in lambda db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8690, in count return db._adapter.count(self.query,distinct) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1597, in count self.execute(self._count(query, distinct)) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1653, in execute return self.log_execute(*a, **b) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1647, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: Cannot operate on a closed database. I put the code of the simple app in a new app with the latest web2py, the first time I accessed the page all worked well but when I reloaded it, I got the error. Hope this can help you. Best, Paolo 2012/8/31 Massimo Di Pierro massimo@gmail.com: What's the error? Works for me. On Friday, 31 August 2012 16:00:24 UTC-5, Paolo wrote: Hi Massimo, I made a simple app, accordingly this example the error seems related to the cache, because without the cache all works fine. The model: db.define_table('reviews_like_s', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews_s', Field('title')) db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) db.reviews_s.neg = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == False)).count() ) Function: def test(): id = db.reviews_s.insert(title='xxx') db.reviews_like_s.insert(review_id=id, helpful=True) rows = db(db.reviews_s.id 0).select( cache=(cache.ram,3600) ) return dict(reviews=rows) The view: {{for review in reviews:}} p{{=review.pos()}}/p {{pass}} On my side the first time works well, the second rises the error. Best, Paolo 2012/8/30 paolo@gmail.com paolo@gmail.com: Hi Massimo, no, I do not have multiple models, I have defined the string connection only once in db.py, that's all. I have a few try...except but in other places, I do not thing they are connected. I will try to make a simple app ables to reproduce the problem as soon as possible. Paolo 2012/8/30 Massimo Di Pierro massimo@gmail.com: Can you make a simple app to reproduce this? Do you have try except anywhere? Do you have multiple models wich define the same db = DAL(...) connection? On Thursday, 30 August 2012 15:49:01 UTC-5, Paolo wrote: Hi Bruno, a simple db with sqlite without modules db = DAL('sqlite://storage.sqlite',
Re: [web2py] Re: Lazy_tables with virtual fields
Hi Massimo, I've just tried both strategies you suggested but I got the same behavior; namely the first time it works, the second rises the error. Paolo 2012/9/1 Massimo Di Pierro massimo.dipie...@gmail.com: I do not fully understand this. It mush have something to do with the scoping of variables in python. Can you try replace db.reviews.pos = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) with db.reviews.pos = Field.Lazy(lambda row,db=db: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row,db=db: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) or with def lazy1(row,db=db): return db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() def lazy2(row,db=db): return db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() db.reviews.pos = Field.Lazy(lazy1) db.reviews.neg = Field.Lazy(lazy2) On Saturday, 1 September 2012 05:50:35 UTC-5, João Saraiva wrote: Hello, Could it be something related to Dropbox's sync mechanism? Have you tried running your app in another folder outside of Dropbox's reach? Would probably explain why your example works fine on other user's machines. Best regards, JS On Saturday, September 1, 2012 6:34:39 AM UTC+1, Paolo wrote: Hi Massimo, the error is: Cannot operate on a closed database. ticket: Traceback (most recent call last): File /home/paolo/Dropbox/git/pp/web2py/gluon/restricted.py, line 209, in restricted exec ccode in environment File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/views/default/test.html, line 3, in module {{pass}} File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8825, in __call__ return self.method(self.row,*args,**kwargs) File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/models/db.py, line 129, in lambda db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8690, in count return db._adapter.count(self.query,distinct) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1597, in count self.execute(self._count(query, distinct)) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1653, in execute return self.log_execute(*a, **b) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1647, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: Cannot operate on a closed database. I put the code of the simple app in a new app with the latest web2py, the first time I accessed the page all worked well but when I reloaded it, I got the error. Hope this can help you. Best, Paolo 2012/8/31 Massimo Di Pierro massimo@gmail.com: What's the error? Works for me. On Friday, 31 August 2012 16:00:24 UTC-5, Paolo wrote: Hi Massimo, I made a simple app, accordingly this example the error seems related to the cache, because without the cache all works fine. The model: db.define_table('reviews_like_s', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews_s', Field('title')) db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) db.reviews_s.neg = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == False)).count() ) Function: def test(): id = db.reviews_s.insert(title='xxx') db.reviews_like_s.insert(review_id=id, helpful=True) rows = db(db.reviews_s.id 0).select( cache=(cache.ram,3600) ) return dict(reviews=rows) The view: {{for review in reviews:}} p{{=review.pos()}}/p {{pass}} On my side the first time works well, the second rises the error. Best, Paolo 2012/8/30 paolo@gmail.com paolo@gmail.com: Hi Massimo, no, I do not have multiple models, I have defined the string connection only once in db.py, that's all. I have a few try...except but in other places, I do not thing they are connected. I will try to make a simple app ables to reproduce the problem as soon as possible. Paolo 2012/8/30 Massimo Di Pierro massimo@gmail.com: Can you make a simple app to reproduce this? Do you have try except anywhere? Do you have multiple models wich define the same db = DAL(...) connection? On Thursday, 30 August 2012 15:49:01 UTC-5, Paolo
Re: [web2py] Re: Lazy_tables with virtual fields
One more test: def getdb(): return db db.reviews.pos = Field.Lazy(lambda row,db=getdb: db()((db().reviews_like.review_id == row.reviews.id) (db().reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row,db=getdb: db()((db().reviews_like.review_id == row.reviews.id) (db().reviews_like.helpful == False)).count() ) Notice you can also do db.reviews.pos = Field.Virtual(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Virtual(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) and use rows.pos instead of rows.pos() In this case the value is cached, not the callback function. On Saturday, 1 September 2012 07:40:20 UTC-5, Paolo wrote: Hi Massimo, I've just tried both strategies you suggested but I got the same behavior; namely the first time it works, the second rises the error. Paolo 2012/9/1 Massimo Di Pierro massimo@gmail.com javascript:: I do not fully understand this. It mush have something to do with the scoping of variables in python. Can you try replace db.reviews.pos = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) with db.reviews.pos = Field.Lazy(lambda row,db=db: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row,db=db: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) or with def lazy1(row,db=db): return db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() def lazy2(row,db=db): return db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() db.reviews.pos = Field.Lazy(lazy1) db.reviews.neg = Field.Lazy(lazy2) On Saturday, 1 September 2012 05:50:35 UTC-5, João Saraiva wrote: Hello, Could it be something related to Dropbox's sync mechanism? Have you tried running your app in another folder outside of Dropbox's reach? Would probably explain why your example works fine on other user's machines. Best regards, JS On Saturday, September 1, 2012 6:34:39 AM UTC+1, Paolo wrote: Hi Massimo, the error is: Cannot operate on a closed database. ticket: Traceback (most recent call last): File /home/paolo/Dropbox/git/pp/web2py/gluon/restricted.py, line 209, in restricted exec ccode in environment File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/views/default/test.html, line 3, in module {{pass}} File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8825, in __call__ return self.method(self.row,*args,**kwargs) File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/models/db.py, line 129, in lambda db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8690, in count return db._adapter.count(self.query,distinct) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1597, in count self.execute(self._count(query, distinct)) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1653, in execute return self.log_execute(*a, **b) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1647, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: Cannot operate on a closed database. I put the code of the simple app in a new app with the latest web2py, the first time I accessed the page all worked well but when I reloaded it, I got the error. Hope this can help you. Best, Paolo 2012/8/31 Massimo Di Pierro massimo@gmail.com: What's the error? Works for me. On Friday, 31 August 2012 16:00:24 UTC-5, Paolo wrote: Hi Massimo, I made a simple app, accordingly this example the error seems related to the cache, because without the cache all works fine. The model: db.define_table('reviews_like_s', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews_s', Field('title')) db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) db.reviews_s.neg = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == False)).count() )
Re: [web2py] Re: Lazy_tables with virtual fields
Hi Massimo, first of all thank you for spending time on it! The first test ends as the others, namely the first time it works, then it raises an error. The the second test works without any problem :-) To solve the issue, I will change the code to follow what you have suggested in the second test. Cheers, Paolo 2012/9/1 Massimo Di Pierro massimo.dipie...@gmail.com: One more test: def getdb(): return db db.reviews.pos = Field.Lazy(lambda row,db=getdb: db()((db().reviews_like.review_id == row.reviews.id) (db().reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row,db=getdb: db()((db().reviews_like.review_id == row.reviews.id) (db().reviews_like.helpful == False)).count() ) Notice you can also do db.reviews.pos = Field.Virtual(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Virtual(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) and use rows.pos instead of rows.pos() In this case the value is cached, not the callback function. On Saturday, 1 September 2012 07:40:20 UTC-5, Paolo wrote: Hi Massimo, I've just tried both strategies you suggested but I got the same behavior; namely the first time it works, the second rises the error. Paolo 2012/9/1 Massimo Di Pierro massimo@gmail.com: I do not fully understand this. It mush have something to do with the scoping of variables in python. Can you try replace db.reviews.pos = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) with db.reviews.pos = Field.Lazy(lambda row,db=db: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row,db=db: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) or with def lazy1(row,db=db): return db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() def lazy2(row,db=db): return db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() db.reviews.pos = Field.Lazy(lazy1) db.reviews.neg = Field.Lazy(lazy2) On Saturday, 1 September 2012 05:50:35 UTC-5, João Saraiva wrote: Hello, Could it be something related to Dropbox's sync mechanism? Have you tried running your app in another folder outside of Dropbox's reach? Would probably explain why your example works fine on other user's machines. Best regards, JS On Saturday, September 1, 2012 6:34:39 AM UTC+1, Paolo wrote: Hi Massimo, the error is: Cannot operate on a closed database. ticket: Traceback (most recent call last): File /home/paolo/Dropbox/git/pp/web2py/gluon/restricted.py, line 209, in restricted exec ccode in environment File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/views/default/test.html, line 3, in module {{pass}} File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8825, in __call__ return self.method(self.row,*args,**kwargs) File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/models/db.py, line 129, in lambda db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8690, in count return db._adapter.count(self.query,distinct) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1597, in count self.execute(self._count(query, distinct)) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1653, in execute return self.log_execute(*a, **b) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1647, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: Cannot operate on a closed database. I put the code of the simple app in a new app with the latest web2py, the first time I accessed the page all worked well but when I reloaded it, I got the error. Hope this can help you. Best, Paolo 2012/8/31 Massimo Di Pierro massimo@gmail.com: What's the error? Works for me. On Friday, 31 August 2012 16:00:24 UTC-5, Paolo wrote: Hi Massimo, I made a simple app, accordingly this example the error seems related to the cache, because without the cache all works fine. The model: db.define_table('reviews_like_s', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews_s', Field('title')) db.reviews_s.pos = Field.Lazy(lambda row:
Re: [web2py] Re: Lazy_tables with virtual fields
Hi Massimo, I made a simple app, accordingly this example the error seems related to the cache, because without the cache all works fine. The model: db.define_table('reviews_like_s', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews_s', Field('title')) db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) db.reviews_s.neg = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == False)).count() ) Function: def test(): id = db.reviews_s.insert(title='xxx') db.reviews_like_s.insert(review_id=id, helpful=True) rows = db(db.reviews_s.id 0).select( cache=(cache.ram,3600) ) return dict(reviews=rows) The view: {{for review in reviews:}} p{{=review.pos()}}/p {{pass}} On my side the first time works well, the second rises the error. Best, Paolo 2012/8/30 paolo.vall...@gmail.com paolo.vall...@gmail.com: Hi Massimo, no, I do not have multiple models, I have defined the string connection only once in db.py, that's all. I have a few try...except but in other places, I do not thing they are connected. I will try to make a simple app ables to reproduce the problem as soon as possible. Paolo 2012/8/30 Massimo Di Pierro massimo.dipie...@gmail.com: Can you make a simple app to reproduce this? Do you have try except anywhere? Do you have multiple models wich define the same db = DAL(...) connection? On Thursday, 30 August 2012 15:49:01 UTC-5, Paolo wrote: Hi Bruno, a simple db with sqlite without modules db = DAL('sqlite://storage.sqlite', lazy_tables=True ) sorry, but I've just discovered that the same problem is happened even with lazy_tables=False Paolo 2012/8/30 Bruno Rocha rocha...@gmail.com: How are you defining the db connection? are you using models or modules? which db? -- -- Paolo -- -- Paolo -- Paolo --
Re: [web2py] Re: Lazy_tables with virtual fields
What's the error? Works for me. On Friday, 31 August 2012 16:00:24 UTC-5, Paolo wrote: Hi Massimo, I made a simple app, accordingly this example the error seems related to the cache, because without the cache all works fine. The model: db.define_table('reviews_like_s', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews_s', Field('title')) db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) db.reviews_s.neg = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == False)).count() ) Function: def test(): id = db.reviews_s.insert(title='xxx') db.reviews_like_s.insert(review_id=id, helpful=True) rows = db(db.reviews_s.id 0).select( cache=(cache.ram,3600) ) return dict(reviews=rows) The view: {{for review in reviews:}} p{{=review.pos()}}/p {{pass}} On my side the first time works well, the second rises the error. Best, Paolo 2012/8/30 paolo@gmail.com javascript: paolo@gmail.comjavascript:: Hi Massimo, no, I do not have multiple models, I have defined the string connection only once in db.py, that's all. I have a few try...except but in other places, I do not thing they are connected. I will try to make a simple app ables to reproduce the problem as soon as possible. Paolo 2012/8/30 Massimo Di Pierro massimo@gmail.com javascript:: Can you make a simple app to reproduce this? Do you have try except anywhere? Do you have multiple models wich define the same db = DAL(...) connection? On Thursday, 30 August 2012 15:49:01 UTC-5, Paolo wrote: Hi Bruno, a simple db with sqlite without modules db = DAL('sqlite://storage.sqlite', lazy_tables=True ) sorry, but I've just discovered that the same problem is happened even with lazy_tables=False Paolo 2012/8/30 Bruno Rocha rocha...@gmail.com: How are you defining the db connection? are you using models or modules? which db? -- -- Paolo -- -- Paolo -- Paolo --
Re: [web2py] Re: Lazy_tables with virtual fields
Hi Massimo, the error is: Cannot operate on a closed database. ticket: Traceback (most recent call last): File /home/paolo/Dropbox/git/pp/web2py/gluon/restricted.py, line 209, in restricted exec ccode in environment File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/views/default/test.html, line 3, in module {{pass}} File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8825, in __call__ return self.method(self.row,*args,**kwargs) File /home/paolo/Dropbox/git/pp/web2py/applications/test_vf/models/db.py, line 129, in lambda db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 8690, in count return db._adapter.count(self.query,distinct) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1597, in count self.execute(self._count(query, distinct)) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1653, in execute return self.log_execute(*a, **b) File /home/paolo/Dropbox/git/pp/web2py/gluon/dal.py, line 1647, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: Cannot operate on a closed database. I put the code of the simple app in a new app with the latest web2py, the first time I accessed the page all worked well but when I reloaded it, I got the error. Hope this can help you. Best, Paolo 2012/8/31 Massimo Di Pierro massimo.dipie...@gmail.com: What's the error? Works for me. On Friday, 31 August 2012 16:00:24 UTC-5, Paolo wrote: Hi Massimo, I made a simple app, accordingly this example the error seems related to the cache, because without the cache all works fine. The model: db.define_table('reviews_like_s', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews_s', Field('title')) db.reviews_s.pos = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == True)).count() ) db.reviews_s.neg = Field.Lazy(lambda row: db((db.reviews_like_s.review_id == row.reviews_s.id) (db.reviews_like_s.helpful == False)).count() ) Function: def test(): id = db.reviews_s.insert(title='xxx') db.reviews_like_s.insert(review_id=id, helpful=True) rows = db(db.reviews_s.id 0).select( cache=(cache.ram,3600) ) return dict(reviews=rows) The view: {{for review in reviews:}} p{{=review.pos()}}/p {{pass}} On my side the first time works well, the second rises the error. Best, Paolo 2012/8/30 paolo@gmail.com paolo@gmail.com: Hi Massimo, no, I do not have multiple models, I have defined the string connection only once in db.py, that's all. I have a few try...except but in other places, I do not thing they are connected. I will try to make a simple app ables to reproduce the problem as soon as possible. Paolo 2012/8/30 Massimo Di Pierro massimo@gmail.com: Can you make a simple app to reproduce this? Do you have try except anywhere? Do you have multiple models wich define the same db = DAL(...) connection? On Thursday, 30 August 2012 15:49:01 UTC-5, Paolo wrote: Hi Bruno, a simple db with sqlite without modules db = DAL('sqlite://storage.sqlite', lazy_tables=True ) sorry, but I've just discovered that the same problem is happened even with lazy_tables=False Paolo 2012/8/30 Bruno Rocha rocha...@gmail.com: How are you defining the db connection? are you using models or modules? which db? -- -- Paolo -- -- Paolo -- Paolo -- -- Paolo --
[web2py] Re: Lazy_tables with virtual fields
I tried this (2.0.2) and I cannot reproduce the problem: db = DAL(lazy_tables=True) db.define_table('reviews_like', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews', Field('title')) db.reviews.pos = Field.Lazy(lambda row: db((db.reviews_like.review_id == ro\ w.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row: db((db.reviews_like.review_id == ro\ w.reviews.id) (db.reviews_like.helpful == False)).count() ) id = db.reviews.insert(title='xxx') db.reviews_like.insert(review_id=id, helpful=True) print db(db.reviews_like.review_id==db.reviews.id).select() On Thursday, 30 August 2012 11:16:27 UTC-5, Paolo wrote: Dear all, I just updated web2py and after turning on the lazy_table I got: Traceback (most recent call last): File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 209, in restricted exec ccode in environment File /home/paolo/Dropbox/git/web2py/applications/bikend/views/load/reviewsFilter.html, line 57, in module var str = '{{=T('Route ')}}smallNAME /smallb class=caret /b'.replace(/NAME/gi, $(this).text()); File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 8810, in __call__ return self.method(self.row,*args,**kwargs) File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py http://127.0.0.1:8000/admin/default/edit/bikend/models/db.py, line 427, in lambda db.reviews.pos = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 8675, in count return db._adapter.count(self.query,distinct) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1542, in count self.execute(self._count(query, distinct)) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1598, in execute return self.log_execute(*a, **b) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1592, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: Cannot operate on a closed database. The table involved in the error is defined as follows: db.define_table('reviews_like', Field('review_id', 'reference reviews'), Field('helpful', 'boolean', widget = BuildRadioButtonWidget), Field('created_on', 'datetime', default=request.now, writable = False, readable = False), Field('user_id', db.auth_user, default=auth.user_id, writable = False, readable = False) ) db.define_table('reviews', Field('route_id', 'reference route', default=db.route.id), Field('rating', 'integer',requires=IS_IN_SET(range(1,6))), Field('title', 'string', requires=(IS_NOT_EMPTY(error_message=T('Enter a title')),IS_LENGTH(250,error_message=T('Warning, title too long')), IS_LENGTH(minsize=3, error_message=T('Warning, title too short', Field('description', 'text', requires=(IS_NOT_EMPTY(error_message=T('Please, enter a description')),IS_LENGTH(250,error_message=T('Warning, description too long')), IS_LENGTH(minsize=75, error_message=T('Warning, the description is too short, reviews must be at least 75 characters long.', auth.signature, ) db.reviews.route_id.readable = False db.reviews.route_id.writable = False db.reviews.rating.widget = starWidget db.reviews.pos = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == False)).count() ) what is wrong ? Cheers Paolo --
Re: [web2py] Re: Lazy_tables with virtual fields
Hi Massimo, actually I do not know, it seems to be a very odd error; I've just restarted web2py and the problem has seemed gone but unfortunately, after a while it came back in a totally different fashion: Traceback (most recent call last): File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 209, in restricted exec ccode in environment File /home/paolo/Dropbox/git/web2py/applications/bikend/views/route/routesListWrapper.html, line 981, in module File /home/paolo/Dropbox/git/web2py/applications/bikend/models/routeDB.py, line 27, in get_route_a content = get_route_img(id=route.route.id) File /home/paolo/Dropbox/git/web2py/applications/bikend/models/routeDB.py, line 56, in get_route_img img = get_img(route.route.photo_id, True) File /home/paolo/Dropbox/git/web2py/applications/bikend/models/1_extra.py, line 94, in get_img if picture and picture.picture: File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7273, in __getattr__ self.__allocate() File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7266, in __allocate self._record = self._table[int(self)] File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 7551, in __getitem__ return self._db(self._id == key).select(limitby=(0,1)).first() File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 8682, in select return adapter.select(self.query,fields,attributes) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 2022, in select return super(SQLiteAdapter, self).select(query, fields, attributes) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1522, in select return self._select_aux(sql,fields,attributes) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1495, in _select_aux self.execute(sql) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1598, in execute return self.log_execute(*a, **b) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1592, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: Cannot operate on a closed database. I do not know, maybe there is something wrong with my application rather than with web2py Paolo 2012/8/30 Massimo Di Pierro massimo.dipie...@gmail.com: I tried this (2.0.2) and I cannot reproduce the problem: db = DAL(lazy_tables=True) db.define_table('reviews_like', Field('review_id', 'reference reviews'), Field('helpful', 'boolean')) db.define_table('reviews', Field('title')) db.reviews.pos = Field.Lazy(lambda row: db((db.reviews_like.review_id == ro\ w.reviews.id) (db.reviews_like.helpful == True)).count() ) db.reviews.neg = Field.Lazy(lambda row: db((db.reviews_like.review_id == ro\ w.reviews.id) (db.reviews_like.helpful == False)).count() ) id = db.reviews.insert(title='xxx') db.reviews_like.insert(review_id=id, helpful=True) print db(db.reviews_like.review_id==db.reviews.id).select() On Thursday, 30 August 2012 11:16:27 UTC-5, Paolo wrote: Dear all, I just updated web2py and after turning on the lazy_table I got: Traceback (most recent call last): File /home/paolo/Dropbox/git/web2py/gluon/restricted.py, line 209, in restricted exec ccode in environment File /home/paolo/Dropbox/git/web2py/applications/bikend/views/load/reviewsFilter.html, line 57, in module var str = '{{=T('Route ')}}smallNAME /smallb class=caret /b'.replace(/NAME/gi, $(this).text()); File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 8810, in __call__ return self.method(self.row,*args,**kwargs) File /home/paolo/Dropbox/git/web2py/applications/bikend/models/db.py, line 427, in lambda db.reviews.pos = Field.Lazy(lambda row: db((db.reviews_like.review_id == row.reviews.id) (db.reviews_like.helpful == True)).count() ) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 8675, in count return db._adapter.count(self.query,distinct) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1542, in count self.execute(self._count(query, distinct)) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1598, in execute return self.log_execute(*a, **b) File /home/paolo/Dropbox/git/web2py/gluon/dal.py, line 1592, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: Cannot operate on a closed database. The table involved in the error is defined as follows: db.define_table('reviews_like', Field('review_id', 'reference reviews'), Field('helpful', 'boolean', widget = BuildRadioButtonWidget), Field('created_on', 'datetime', default=request.now, writable = False, readable = False), Field('user_id', db.auth_user, default=auth.user_id, writable = False, readable = False) ) db.define_table('reviews', Field('route_id', 'reference route', default=db.route.id), Field('rating',
Re: [web2py] Re: Lazy_tables with virtual fields
How are you defining the db connection? are you using models or modules? which db? --
Re: [web2py] Re: Lazy_tables with virtual fields
Hi Bruno, a simple db with sqlite without modules db = DAL('sqlite://storage.sqlite', lazy_tables=True ) sorry, but I've just discovered that the same problem is happened even with lazy_tables=False Paolo 2012/8/30 Bruno Rocha rochacbr...@gmail.com: How are you defining the db connection? are you using models or modules? which db? -- -- Paolo --
Re: [web2py] Re: Lazy_tables with virtual fields
Can you make a simple app to reproduce this? Do you have try except anywhere? Do you have multiple models wich define the same db = DAL(...) connection? On Thursday, 30 August 2012 15:49:01 UTC-5, Paolo wrote: Hi Bruno, a simple db with sqlite without modules db = DAL('sqlite://storage.sqlite', lazy_tables=True ) sorry, but I've just discovered that the same problem is happened even with lazy_tables=False Paolo 2012/8/30 Bruno Rocha rocha...@gmail.com javascript:: How are you defining the db connection? are you using models or modules? which db? -- -- Paolo --
Re: [web2py] Re: Lazy_tables with virtual fields
Hi Massimo, no, I do not have multiple models, I have defined the string connection only once in db.py, that's all. I have a few try...except but in other places, I do not thing they are connected. I will try to make a simple app ables to reproduce the problem as soon as possible. Paolo 2012/8/30 Massimo Di Pierro massimo.dipie...@gmail.com: Can you make a simple app to reproduce this? Do you have try except anywhere? Do you have multiple models wich define the same db = DAL(...) connection? On Thursday, 30 August 2012 15:49:01 UTC-5, Paolo wrote: Hi Bruno, a simple db with sqlite without modules db = DAL('sqlite://storage.sqlite', lazy_tables=True ) sorry, but I've just discovered that the same problem is happened even with lazy_tables=False Paolo 2012/8/30 Bruno Rocha rocha...@gmail.com: How are you defining the db connection? are you using models or modules? which db? -- -- Paolo -- -- Paolo --