1

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?

Community
  • 1
  • 1
Rafael T
  • 15,401
  • 15
  • 83
  • 144
  • 2
    Looking at the [code](https://github.com/coleifer/peewee/blob/master/peewee.py#L2861) it looks like the `Meta` class gets converted to a `ModelOptions` instance, available at `ModelObj._meta`. – univerio May 15 '14 at 01:04
  • Did you try with a instance of ModelObj? ModelObj().Meta.database – andmart May 15 '14 at 01:20

0 Answers0