Skip to content
This repository was archived by the owner on May 3, 2020. It is now read-only.

Commit 27bf3e3

Browse files
committed
Merge pull request #18 from jirikuncar/autodiscovery-app-fix
Fix issue with app in ModuleAutoDiscoveryRegistry
2 parents 329e3b9 + 107cf67 commit 27bf3e3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

flask_registry/registries/modulediscovery.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,7 @@ def __init__(self, module_name, app=None, registry_namespace=None,
248248
module_name, with_setup=with_setup, silent=silent,
249249
registry_namespace=registry_namespace
250250
)
251+
if app is None and has_app_context():
252+
app = current_app
251253
self.app = app
252254
self.discover(app=app)

tests/test_modulediscovery.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,22 @@ def test_registration(self):
217217
assert len(self.app.extensions['registry']['myns']) == 1
218218
from flask_registry.registries import appdiscovery
219219
assert self.app.extensions['registry']['myns'][0] == appdiscovery
220+
221+
def test_registry_proxy(self):
222+
Registry(app=self.app)
223+
224+
self.app.extensions['registry']['pathns'] = \
225+
ImportPathRegistry(initial=['flask_registry.*'])
226+
227+
myns = RegistryProxy(
228+
'myns', ModuleAutoDiscoveryRegistry, 'appdiscovery',
229+
registry_namespace='pathns'
230+
)
231+
232+
with self.app.app_context():
233+
assert len(self.app.extensions['registry']['pathns']) == 2
234+
assert len(list(myns)) == 1
235+
from flask_registry.registries import appdiscovery
236+
assert myns[0] == appdiscovery
237+
238+

0 commit comments

Comments
 (0)