I'm using Peewee and bottle.py for a very small WebApp. Once in a while I get a MySQLDatabase has gone away Error
, which my script doesn't seem to recover from.
According to this answer, I should simply try-catch the error and recover myself. An example of what I have:
def create_db_con():
return peewee.MySQLDatabase("db_name", host="host", user="user", passwd="pass")
class ModelObj(peewee.Model):
#some member ommited
class Meta:
database=create_db_con()
@route("/")
def index_htm():
try:
mo = ModelObj.filter(foo="bar")
catch OperationalError, oe:
ModelObj.Meta.database = create_db_con()
gives me the AttributeError in case of the OperationalError:
AttributeError: type object 'OrderProdukt' has no attribute 'Meta'
How am I supposed to recover from this situation?
EDIT:
As univerio pointed out, I can access it via ModelObj._meta.database
, but it doesn't seem to work to just create it new.
Is this a default python behavior for nested classes?