Skip to content

Commit

Permalink
Fix MethodViewResolver instantiating multiple instances of a view (#1310
Browse files Browse the repository at this point in the history
)

Co-authored-by: Robbe Sneyders <[email protected]>
  • Loading branch information
exaroth and RobbeSneyders authored Jul 14, 2021
1 parent 2066503 commit 2d81422
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion connexion/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def post(self):
return ...
"""

def __init__(self, *args, **kwargs):
super(MethodViewResolver, self).__init__(*args, **kwargs)
self.initialized_views = []

def resolve_operation_id(self, operation):
"""
Resolves the operationId using REST semantics unless explicitly configured in the spec
Expand Down Expand Up @@ -190,7 +194,14 @@ def resolve_function_from_operation_id(self, operation_id):
mod = __import__(module_name, fromlist=[view_name])
view_cls = getattr(mod, view_name)
# Find the class and instantiate it
view = view_cls()
view = None
for v in self.initialized_views:
if v.__class__ == view_cls:
view = v
break
if view is None:
view = view_cls()
self.initialized_views.append(view)
func = getattr(view, meth_name)
# Return the method function of the class
return func
Expand Down

0 comments on commit 2d81422

Please sign in to comment.