pydal

SOLVED: AttributeError: ‘_thread._local’ object has no attribute ‘_pydal_connection_140103876850296_30686’

I have been using web2py’s pyDAL with no problem for a long time. However, recently I started getting the error mentioned in the title and this stacktrace.

I googled about and for some reason a certain pyDAL thread came up. And in one of the comments I saw some code which forced a reconnect.

So I took my instance of pyDAL and forced a reconnect before inserting:

def record_buy(config_file, order_id, mkt, rate, amount):
 """Store the details of a coin purchase.

Create a new record in the `buy` table.

Returns:
 Nothing
 """
    db._adapter.reconnect()

    db.buy.insert(
            config_file=config_file,
            order_id=order_id, market=mkt, purchase_price=rate, amount=amount)
    db.commit()



And wallah! No more error!