public
Created

SQLAlchemy raises None, causes TypeError - Test

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Traceback (most recent call last):
File "test_case_9525220.py", line 41, in <module>
session.commit()
File "/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 645, in commit
self.transaction.commit()
File "/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 313, in commit
self._prepare_impl()
File "/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 297, in _prepare_impl
self.session.flush()
File "/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1547, in flush
self._flush(objects)
File "/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1635, in _flush
raise
TypeError: exceptions must be old-style classes or derived from BaseException, not NoneType
test_case_9525220.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
# For http://stackoverflow.com/questions/9525220/sqlalchemy-raises-none-causes-typeerror
 
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy.orm import sessionmaker
import MySQLdb
 
Base = declarative_base()
 
CONNECTION_TYPE = 'mysql_db_pool'
 
class User(Base):
__tablename__ = 'users'
 
id = Column(Integer, primary_key=True, autoincrement=True)
userid = Column(String(50), nullable=False)
 
if __name__ == '__main__':
url = 'mysql://root:root@127.0.0.1:3306/testdb'
 
if CONNECTION_TYPE == 'sqlite':
engine = create_engine('sqlite:///:memory:', echo=True)
elif CONNECTION_TYPE == 'mysql':
engine = create_engine(url)
elif CONNECTION_TYPE == 'mysql_db_pool':
from eventlet.db_pool import ConnectionPool
pool = ConnectionPool(MySQLdb, host='127.0.0.1', user='root', passwd='root', db='testdb')
engine = create_engine(url,
creator=pool.create,
pool_size=pool.max_size,
)
 
session = sessionmaker(bind=engine)()
 
User.metadata.drop_all(bind=engine)
User.metadata.create_all(bind=engine)
 
u = User()
session.add(u)
session.commit()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.