0

In the following code, if I hit /testDbOne I get no errors, if I hit /testDbTWo I get the following error:

TypeError('testDbTwo() takes exactly 1 argument (0 given)',)

If I swap the position of engine1 and engine2, then testDbOne breaks and testDbTwo works. What am I doing wrong that I can't have SQLAlchemy create both sessions and install them into bottle as plugins?

Base = declarative_base()

#engine1
engine_s = create_engine('mysql://user:pass@localhost/dbone', echo=True)
create_session_s = sessionmaker(bind=engine_s)
bottle.install(SQLAlchemyPlugin(engine_s, Base.metadata, keyword="dbone"))

#engine2
engine = create_engine('mysql://user:pass@localhost/dbtwo', echo=True)
create_session = sessionmaker(bind=engine)
bottle.install(SQLAlchemyPlugin(engine, Base.metadata, keyword="dbtwo"))

#create the actual database sessions
dboneSession = create_session_s()
dbTwoSession = create_session()

@route("/testDbOne")
def testUserOne(dbone):
    return "no error here"

@route("/testDbTwo")
def testDbTwo(dbtwo):
    return "no error here"
4

1 回答 1

1

If you add sqlalchemy information to your route, then it starts to work ok. For example:

@route("/testDbOne", sqlalchemy=dict(keyword='dbone'))
def testUserOne(dbone):
    return "no error here"

@route("/testDbTwo", sqlalchemy=dict(keyword='dbtwo'))
def testDbTwo(dbtwo):
    return "no error here"

Seems to work for me.

于 2012-07-18T20:31:29.223 回答