Connexion: It looks like connexion 1.1.6 broke compatibility with flask-injector.

Created on 16 Jun 2017  路  10Comments  路  Source: zalando/connexion

Description

This code https://medium.com/@ssola/building-microservices-with-python-part-i-5240a8dcc2fb section working with Flask Injector does not work.

Expected behaviour

Should work

Actual behaviour

Error message:
TypeError: search() missing 1 required positional argument: 'data_provider'

Steps to reproduce

use connexion 1.1.6 or higher in requirements.txt

Additional info:

Output of the commands:

  • python --version
    3.6

  • pip show connexion | grep "^Version\:"

help wanted

Most helpful comment

Unfortunately I'm not familiar with connexion enough to create a proper automated test (required for a PR as far as I'm concerned) but I was able to verify a patch to connexion against a simple test case and it works. This is the patch:

diff --git a/connexion/decorators/parameter.py b/connexion/decorators/parameter.py
index 54734d8..906163b 100644
--- a/connexion/decorators/parameter.py
+++ b/connexion/decorators/parameter.py
@@ -142,6 +142,12 @@ def parameter_to_arg(parameters, consumes, function, pythonic_params=False):
             logger.debug("Body parameter '%s' in function arguments", body_name)
             kwargs[body_name] = request_body

+        for key, value in path_params.items():
+            if key not in kwargs:
+                kwargs[key] = value
+
         # Add query parameters
         query_arguments = copy.deepcopy(default_query_params)
         query_arguments.update({sanitize_param(k): v for k, v in request.query.items()})

The issue is that keyword arguments to views are silently discarded if they don't correspond to named URL placeholders which interferes with Flask-Injector because Flask-Injector uses exactly that mechanism to provide dependencies.

I hope someone can use the patch above and create a proper connexion change (if it's determined to be desired).

All 10 comments

Thanks for the information, did not know about that!

Will you be able to fix this?

@tjhgit Are you willing to do a PR to fix this?

Hey all, I'm in the process of debugging this so might as well send a PR when I know what's going on.

Unfortunately I'm not familiar with connexion enough to create a proper automated test (required for a PR as far as I'm concerned) but I was able to verify a patch to connexion against a simple test case and it works. This is the patch:

diff --git a/connexion/decorators/parameter.py b/connexion/decorators/parameter.py
index 54734d8..906163b 100644
--- a/connexion/decorators/parameter.py
+++ b/connexion/decorators/parameter.py
@@ -142,6 +142,12 @@ def parameter_to_arg(parameters, consumes, function, pythonic_params=False):
             logger.debug("Body parameter '%s' in function arguments", body_name)
             kwargs[body_name] = request_body

+        for key, value in path_params.items():
+            if key not in kwargs:
+                kwargs[key] = value
+
         # Add query parameters
         query_arguments = copy.deepcopy(default_query_params)
         query_arguments.update({sanitize_param(k): v for k, v in request.query.items()})

The issue is that keyword arguments to views are silently discarded if they don't correspond to named URL placeholders which interferes with Flask-Injector because Flask-Injector uses exactly that mechanism to provide dependencies.

I hope someone can use the patch above and create a proper connexion change (if it's determined to be desired).

I can replicate this issue in 1.1.13 as well. This issue is not present in 1.1.5

I can replicate this on 1.1.9. Is anyone working on this? I can take a crack at it. Is it a matter of taking the patch above and writing some tests for it? (The patch works for me)

@dcarrot2 go ahead :smile:

Still have this problem with connexion v1.3

False alert. Issue solved by specifying arguments names in binder

binder.bind(
  Normalizer,
  Normalizer(foo="bar")
)
# instead of
binder.bind(
  Normalizer,
  Normalizer("bar")
)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

majoros picture majoros  路  5Comments

acidjunk picture acidjunk  路  5Comments

oddjobz picture oddjobz  路  3Comments

hjacobs picture hjacobs  路  4Comments

bioslikk picture bioslikk  路  4Comments