Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Multiple plugins can't inject parameters #295
I am trying to write a plugin which injects some data into the the functions, but it failes if I already have another plugin (say sqlite).
A simple example is the code below:
from bottle import * import bottle from bottle.ext import sqlite app = bottle.Bottle() test_db = sqlite.Plugin(dbfile='test.db') cache_db = sqlite.Plugin(dbfile=':memory:', keyword='cache') app.install(test_db) app.install(cache_db) @app.route('/') def show(db, cache): return "successfully loaded both plugins" if __name__ == "__main__": run(app, reloader=True)
when run, it throws this error :
from bottle import * import bottle from bottle.ext import sqlite from bottle.ext import memcache app = bottle.Bottle() test_db = sqlite.Plugin(dbfile=':memory:', keyword='cache') app.install(test_db) test_mc = memcache.MemcachePlugin(servers=['localhost:11211']) app.install(test_mc) @app.route('/') def show(db, mc): return "successfully loaded both plugins" if __name__ == "__main__": run(app, reloader=True)
Will yield the following stack trace:
Traceback (most recent call last):
Using the following versions:
Looks like bottle-sqlalchemy has a bug. :/
It override the callback parameter with original callback (without plugins applied). Probably memcache plugin is applied first and sqlalchemy breaks that. I'll investigate this bug soon.
I checked your examples, they break here too.
When correcting this related issue in bottle-sqlalchemy, I added some tests to these cases and it works with all bottle versions: https://github.com/iurisilvio/bottle-sqlalchemy/blob/master/test.py#L147
Today I even tested use bottle-sqlalchemy with bottle-sqlite and bottle-sqlalchemy with bottle-memcache. Both works. I really didn't understand the difference between them to break.
Wow, of course I know what is happening. Your first example use two plugins with the same name. I guess only bottle<0.10 allows it. Your second example use sqlite plugin with keyword='cache', but your route expect a 'db' parameter.
I don't like bottle rejecting two instances of the same plugin. :(