Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: guarantee extensions order #250

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion sea/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,19 @@ 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
ORDER_ATTR = "load_order"
DEFAULT_LOWER_ORDER = 10

if ORDER_ATTR in ext.__dict__:
return getattr(ext, ORDER_ATTR)
return 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
Loading