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

[Bug] Sanic serving request before injection complete #203

Open
trungtin opened this issue Jun 15, 2023 · 1 comment
Open

[Bug] Sanic serving request before injection complete #203

trungtin opened this issue Jun 15, 2023 · 1 comment

Comments

@trungtin
Copy link

trungtin commented Jun 15, 2023

Describe the bug
I did set app.config.INJECTION_SIGNAL = "http.handler.before", but when the server start, there is a split second where the handler runs before the injection finish, and it will throw an error with missing param.

In a normal situation, this wouldn't be an issue, but when using auto scaling (like Google Cloud Run), the instance is spun up to serve the request, then the first request will always result in a 500 error.

Expected behavior
The handler will be called after the injection finish

Environment (please complete the following information):

  • OS: docker python-3.11-slim / MacOS
  • Versions:
    sanic==23.3.0
    sanic-ext==23.3.0
@trungtin
Copy link
Author

After posting this, I realize that it is probably due to my init function being asynchronous. So any suggestion how to deal with that?

@dataclass
class Realm:
    @classmethod
    async def from_header(cls, request: Request):
        # do something here
        return cls()
        
app.ext.add_dependency(Realm, Realm.from_header)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant