New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple plugins can't inject parameters #295

Open
hitezh opened this Issue Mar 6, 2012 · 11 comments

Comments

Projects
None yet
4 participants
@hitezh

hitezh commented Mar 6, 2012

Hi,

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 : TypeError: show() takes exactly 2 arguments (0 given)

@hitezh

This comment has been minimized.

Show comment
Hide comment
@hitezh

hitezh Mar 6, 2012

this looks similar to issue #207 and #231 There the view decorator is conflicting with the sqlite plugin, and in my case another plugin is conflicting.

Can I apply the same workaround here?

hitezh commented Mar 6, 2012

this looks similar to issue #207 and #231 There the view decorator is conflicting with the sqlite plugin, and in my case another plugin is conflicting.

Can I apply the same workaround here?

@iurisilvio

This comment has been minimized.

Show comment
Hide comment
@iurisilvio

iurisilvio Mar 13, 2012

Member

No, that is not the case. I guess since v0.10, bottle doesn't allow two plugins with the same name.

It is an issue to me too.

Member

iurisilvio commented Mar 13, 2012

No, that is not the case. I guess since v0.10, bottle doesn't allow two plugins with the same name.

It is an issue to me too.

@thekad

This comment has been minimized.

Show comment
Hide comment
@thekad

thekad Mar 21, 2012

Is not plugins with the same name, i have two completely different plugins (sqlalchemy and memcache) and I have the same issue, can't use both of them at the same time, don't matter if I use apply[db_plugin, mc_plugin]

thekad commented Mar 21, 2012

Is not plugins with the same name, i have two completely different plugins (sqlalchemy and memcache) and I have the same issue, can't use both of them at the same time, don't matter if I use apply[db_plugin, mc_plugin]

@thekad

This comment has been minimized.

Show comment
Hide comment
@thekad

thekad Mar 21, 2012

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):
File "/Users/kad/git/pasttle/env/lib/python2.7/site-packages/bottle.py", line 737, in _handle
return route.call(*_args)
File "/Users/kad/git/pasttle/env/lib/python2.7/site-packages/bottle.py", line 1456, in wrapper
rv = callback(_a, *_ka)
File "/Users/kad/git/pasttle/env/lib/python2.7/site-packages/bottle_memcache.py", line 39, in wrapper
rv = callback(_args, **kwargs)
TypeError: show() takes exactly 2 arguments (1 given)

Using the following versions:

bottle==0.10.9
bottle-memcache==0.1
bottle-sqlite==0.1.2

thekad commented Mar 21, 2012

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):
File "/Users/kad/git/pasttle/env/lib/python2.7/site-packages/bottle.py", line 737, in _handle
return route.call(*_args)
File "/Users/kad/git/pasttle/env/lib/python2.7/site-packages/bottle.py", line 1456, in wrapper
rv = callback(_a, *_ka)
File "/Users/kad/git/pasttle/env/lib/python2.7/site-packages/bottle_memcache.py", line 39, in wrapper
rv = callback(_args, **kwargs)
TypeError: show() takes exactly 2 arguments (1 given)

Using the following versions:

bottle==0.10.9
bottle-memcache==0.1
bottle-sqlite==0.1.2

@iurisilvio

This comment has been minimized.

Show comment
Hide comment
@iurisilvio

iurisilvio Mar 21, 2012

Member

https://github.com/iurisilvio/bottle-sqlalchemy/blob/master/bottle_sqlalchemy.py#L104

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.

Member

iurisilvio commented Mar 21, 2012

https://github.com/iurisilvio/bottle-sqlalchemy/blob/master/bottle_sqlalchemy.py#L104

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.

@iurisilvio

This comment has been minimized.

Show comment
Hide comment
@iurisilvio

iurisilvio Mar 22, 2012

Member

Seriously, yesterday I read this thread thinking you are using bottle-sqlalchemy to test it. My last comment here makes no sense here. =/

Member

iurisilvio commented Mar 22, 2012

Seriously, yesterday I read this thread thinking you are using bottle-sqlalchemy to test it. My last comment here makes no sense here. =/

@thekad

This comment has been minimized.

Show comment
Hide comment
@thekad

thekad Mar 29, 2012

Hah, yeah indeed makes no sense... this is an issue with any set of plugins, no clue what really is going on

thekad commented Mar 29, 2012

Hah, yeah indeed makes no sense... this is an issue with any set of plugins, no clue what really is going on

@iurisilvio

This comment has been minimized.

Show comment
Hide comment
@iurisilvio

iurisilvio Mar 30, 2012

Member

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.

Member

iurisilvio commented Mar 30, 2012

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.

@iurisilvio

This comment has been minimized.

Show comment
Hide comment
@iurisilvio

iurisilvio Mar 30, 2012

Member

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. :(

Member

iurisilvio commented Mar 30, 2012

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. :(

@iurisilvio

This comment has been minimized.

Show comment
Hide comment
@iurisilvio

iurisilvio Mar 31, 2012

Member

If you really need two instances of sqlite (or any other plugin), you can do some workaround...

db1 = sqlite.Plugin(dbfile='test.db')
db2 = sqlite.Plugin(dbfile=':memory:', keyword='cache')
db2.name = 'other name'
app.install(db1)
app.install(db2)
Member

iurisilvio commented Mar 31, 2012

If you really need two instances of sqlite (or any other plugin), you can do some workaround...

db1 = sqlite.Plugin(dbfile='test.db')
db2 = sqlite.Plugin(dbfile=':memory:', keyword='cache')
db2.name = 'other name'
app.install(db1)
app.install(db2)
@benoitm974

This comment has been minimized.

Show comment
Hide comment
@benoitm974

benoitm974 Jan 9, 2017

Trying to solve this for the sqlite plugin with 1st level recursion on wrapped function : bottlepy/bottle-sqlite#14

benoitm974 commented Jan 9, 2017

Trying to solve this for the sqlite plugin with 1st level recursion on wrapped function : bottlepy/bottle-sqlite#14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment