Skip to content
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

DeprecationWarning: Switch to Plugin API v2 #6

Open
em- opened this issue Jul 28, 2016 · 1 comment
Open

DeprecationWarning: Switch to Plugin API v2 #6

em- opened this issue Jul 28, 2016 · 1 comment

Comments

@em-
Copy link

em- commented Jul 28, 2016

Similar to bottlepy/bottle-sqlite#10, bottle now complains when loading the plugin:

/usr/lib/python2.7/dist-packages/bottle.py:527: DeprecationWarning: Switch to Plugin API v2 and access the Route object directly.
  context = self if api > 1 else self._context

See bottlepy/bottle-redis#3 for the way bottle-redis fixed the issue.

@sporian-smckown
Copy link

This change:

diff --git 1/venv/lib/python3.8/site-packages/bottle_pgsql.py.orig 2/venv/lib/python3.8/site-packages/bottle_pgsql.py
index f65f808..b8d5219 100644
--- 1/venv/lib/python3.8/site-packages/bottle_pgsql.py.orig
+++ 2/venv/lib/python3.8/site-packages/bottle_pgsql.py
@@ -51,6 +51,7 @@ class PgSQLPlugin(object):
     '''

     name = 'pgsql'
+    api = 2

     def __init__(self, dsn=None, autocommit=True, dictrows=True, keyword='db'):
         self.dsn = dsn
@@ -68,9 +69,11 @@ class PgSQLPlugin(object):
             if other.keyword == self.keyword:
                 raise PluginError("Found another pgsql plugin with conflicting settings (non-unique keyword).")

-    def apply(self, callback, context):
+    def apply(self, callback, route):
         # Override global configuration with route-specific values.
-        conf = context['config'].get('pgsql') or {}
+        config = route.config
+        _callback = route.callback
+        conf = config.get('pgsql') or {}
         dsn = conf.get('dsn', self.dsn)
         autocommit = conf.get('autocommit', self.autocommit)
         dictrows = conf.get('dictrows', self.dictrows)
@@ -78,7 +81,7 @@ class PgSQLPlugin(object):

         # Test if the original callback accepts a 'db' keyword.
         # Ignore it if it does not need a database handle.
-        args = inspect.getargspec(context['callback'])[0]
+        args = inspect.signature(_callback).parameters
         if keyword not in args:
             return callback

Solves both of these warnings:

venv/lib/python3.8/site-packages/bottle.py:539: DeprecationWarning: Switch to Plugin API v2 and access the Route object directly.
  context = self if api > 1 else self._context
venv/lib/python3.8/site-packages/bottle_pgsql.py:81: DeprecationWarning: inspect.getargspec() is deprecated since Python 3.0, use inspect.signature() or inspect.getfullargspec()
  args = inspect.getargspec(context['callback'])[0]

Tested on Python 3.8.10 using bottle 0.12.25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants