DialectFunctionDispatcher does not support nesting of decorators

Bug #1373568 reported by Mike Bayer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.db
Fix Released
Medium
Mike Bayer

Bug Description

the DialectFunctionDispatcher doesn't support simple nesting of decorators, such as:

    @_init_connection_args.dispatch_for("mysql+mysqlconnector")
    @_init_connection_args.dispatch_for("mysql+mysqldb")
    def _init_connection_args(url, engine_args, **kw):
       # ...

Because the dispatch_for() decorator returns the dispatcher, and not the function (necessary so that the dispatcher remains available even decorating a same-named function), nesting above does not work automatically, you instead get a recursion overflow:

    File "/Users/classic/dev/redhat/openstack/oslo.db/oslo/db/sqlalchemy/utils.py", line 918, in __call__
      self._url_from_target(target), target, arg, kw)
    File "/Users/classic/dev/redhat/openstack/oslo.db/oslo/db/sqlalchemy/utils.py", line 955, in _dispatch_on
      return self._dispatch_on_db_driver(dbname, driver, arg, kw)
    File "/Users/classic/dev/redhat/openstack/oslo.db/oslo/db/sqlalchemy/utils.py", line 1009, in _dispatch_on_db_driver
      if self._invoke_fn(fn, arg, kw) is not None:
    File "/Users/classic/dev/redhat/openstack/oslo.db/oslo/db/sqlalchemy/utils.py", line 958, in _invoke_fn
      return fn(*arg, **kw)
    File "/Users/classic/dev/redhat/openstack/oslo.db/oslo/db/sqlalchemy/utils.py", line 918, in __call__
      self._url_from_target(target), target, arg, kw)
    File "/Users/classic/dev/redhat/openstack/oslo.db/oslo/db/sqlalchemy/utils.py", line 955, in _dispatch_on
      return self._dispatch_on_db_driver(dbname, driver, arg, kw)
    File "/Users/classic/dev/redhat/openstack/oslo.db/oslo/db/sqlalchemy/utils.py", line 1009, in _dispatch_on_db_driver

  The decorator should anticipate this condition and adapt for it.

Mike Bayer (zzzeek)
Changed in oslo.db:
assignee: nobody → Mike Bayer (zzzeek)
Changed in oslo.db:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Davanum Srinivas (DIMS) (dims-v) wrote :

Do we need to fix this in Mitaka zzzeek?

Revision history for this message
Mike Bayer (zzzeek) wrote :

this was fixed in 7a3e091c:

commit 7a3e091c1c9cc9ae6e34279c7c99c9989afd8894
Author: Mike Bayer <email address hidden>
Date: Wed Sep 24 15:04:53 2014 -0400

    Unwrap DialectFunctionDispatcher from itself.

    The DialectFunctionDispatcher.dispatch_for() decorator method
    necessarily returns the dispatcher itself and not the
    decorated function, so that the object can continue to be
    re-used even if the function name is the same as that of the
    dispatcher. In order to support a single function being
    wrapped by the dispatcher multiple times with different
    criteria, dispatch_for() will now check for the last function
    wrapped and use that.

    Change-Id: I331670d9b76ae30e7a666648e7e2d4c72641c9ff
    Closes-Bug: #1373568

Changed in oslo.db:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.