OK, I allready have read all questions about class method decorating, but my case not like them.
def safe_db(foo):
def _inner(*args, **kwargs):
try:
foo(args, kwargs)
return True
except Exception as e:
log.error(e.message)
print e.message
return False
return _inner
class BaseDB(object):
def __init__(self):
self.connection = Connection()
self.db = self.connection.goobi
self.table = None
@safe_db
def create(self, **data):
self.table.insert(data)
def update(self, where, **data):
try:
self.table.update(where, {'$set': data})
return True
except Exception as e:
log.error(e.message)
print e.message
return False
And then I try call method create from inherited class User:
u = User()
u.create(email='i@example.com', password='secrete')
I get exception:
2012-09-08 18:17:18,230 ERROR [hairs.model.user][worker 2] create() takes exactly 1 argument (2 given)
create() takes exactly 1 argument (2 given)
I cant understand how I can decorate class methods of BaseDB, or how I can make exceptions catch and logging less painfull ?
You have an error in your decorator: