I think there is a little issue left: def typecast_json(s, cur): return loads(s) fails if s == None. I'd suggest s.th. like def typecast_json(s, cur): if s is None: return None return loads(s)
psycopg by date:
Соглашаюсь с условиями обработки персональных данных