Wednesday 3 September 2014

Bad database

SQL:

Don't use select * (start) when dealing with an SQL database. It is bad practice. 

Transactions:
Some python code I made a horrible error with one time:

try:
    with self._rw_engine.begin() as connection:
        rs = connection.execute("SQL")
        myobj.a = rs.get("a")
        myobj.b = rs.get("b")
        myobj.c = rs.get("c")
        # myobj loaded
except Exception:
    log.exception('Unhandled exception:')
    raise
else:
    myobj.load_more_from_db()

What is that exception doing there? Surely it is pointless to log it and reraise, why not remove it and put the load_more_from_db call at '# myobj loaded' comment.
Well myobj is created in a transaction and load_more_from_db will use a different transaction which led to a deadlock on certain tests. So watch your scope.


No comments:

Post a Comment