Skip to content

Commit

Permalink
feat: guarantee extension order
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhaidong committed Jun 7, 2024
1 parent 630673e commit b0406aa
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sea/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ def load_extensions_in_module(self, module):
def is_ext(ins):
return not inspect.isclass(ins) and hasattr(ins, "init_app")

for n, ext in inspect.getmembers(module, is_ext):
# guarantee the order of extension initialization by load_order attribute
def sort_ext(member):
_, ext = member
DEFAULT_LOWER_ORDER = 10
return getattr(ext, "load_order", DEFAULT_LOWER_ORDER)

for n, ext in sorted(
inspect.getmembers(module, is_ext), key=sort_ext
):
self._register_extension(n, ext)
return self.extensions

Expand Down

0 comments on commit b0406aa

Please sign in to comment.