AttributeError: type object 'my_table' has no attribute '__tablename__' #453
Closed
Description
Hi,
I am trying to use flask-restless with SQLAlchemy automap in something in the lines of:
# in my config.py
SQLALCHEMY_BINDS = {
'foo': 'mysql://user:pass@host/database_name?charset_latin1',
# ...
}
# somewhere in my flask application
import sqlalchemy.ext.automap
Base = sqlalchemy.ext.automap.automap_base()
import flask.ext.sqlalchemy
SQLA = flask.ext.sqlalchemy.SQLAlchemy()
engine = SQLA.get_engine(application, 'foo')
import sqlalchemy.orm
Session = sqlalchemy.orm.sessionmaker(autocommit=False, autoflush=False, bind=engine)
mysession = sqlalchemy.orm.scoped_session(Session)
Base.prepare(engine, reflect=True)
import flask.ext.restless
manager = flask.ext.restless.APIManager(application, session=mysession)
for table in Base.classes:
# the following fail with the error:
# AttributeError: type object 'my_table_name' has no attribute '__tablename__'
manager.create_api(table, url_prefix='/prefix/foo')
# the workaround is:
blueprint = manager.create_api_blueprint(table, collection_name=table.__name__)
application.register_blueprint(blueprint, url_prefix='/prefix/foo')
I have no idea if it's somehow related to #382.
Libraries versions:
Flask==0.10.1
Flask-Restless==0.17.0
Flask-SQLAlchemy==2.0
Regards.