Skip to content

Commit

Permalink
Fix late dependency registration (#235)
Browse files Browse the repository at this point in the history
* Fix late dependency registration

* make pretty

* Fix ordering of priorities

* Adjust priorities

* Make pretty
  • Loading branch information
ahopkins authored Dec 31, 2023
1 parent e3ff389 commit 0f6f060
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sanic_ext/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sanic.signals import Event


PRIORITY = 100_000_000
PRIORITY = -1_000


class Config(SanicConfig):
Expand Down
4 changes: 3 additions & 1 deletion sanic_ext/extensions/http/cors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from sanic.helpers import Default, _default
from sanic.log import logger

from sanic_ext.config import PRIORITY


WILDCARD_PATTERN = re.compile(r".*")
ORIGIN_HEADER = "access-control-allow-origin"
Expand Down Expand Up @@ -67,7 +69,7 @@ async def _add_cors_headers(request, response):
_add_allow_header(request, response)
_add_methods_header(request, response)

@app.before_server_start
@app.before_server_start(priority=PRIORITY)
async def _assign_cors_settings(app, _):
for group in app.router.groups.values():
_cors = SimpleNamespace()
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/http/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async def trace_handler(request):
)
return raw(message, content_type="message/http")

@app.before_server_start(priority=PRIORITY + 1)
@app.before_server_start(priority=PRIORITY)
def _add_handlers(app, _):
nonlocal auto_head
nonlocal auto_options
Expand Down
2 changes: 1 addition & 1 deletion sanic_ext/extensions/injection/injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _setup_signature_registry(
) -> SignatureRegistry:
registry = SignatureRegistry()

@app.listener("before_server_start", priority=PRIORITY)
@app.listener("before_server_start", priority=PRIORITY - 1)
async def setup_signatures(app, _):
nonlocal registry

Expand Down
3 changes: 2 additions & 1 deletion sanic_ext/extensions/openapi/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sanic.log import logger
from sanic.response import file, html, json

from sanic_ext.config import PRIORITY
from sanic_ext.extensions.openapi.builders import (
OperationStore,
SpecificationBuilder,
Expand Down Expand Up @@ -115,7 +116,7 @@ async def spec(request: Request):
def openapi_config(request: Request):
return json(request.app.config.SWAGGER_UI_CONFIGURATION)

@bp.before_server_start
@bp.before_server_start(priority=PRIORITY)
def build_spec(app, loop):
specification = SpecificationBuilder()
# --------------------------------------------------------------- #
Expand Down

0 comments on commit 0f6f060

Please sign in to comment.