-
-
Notifications
You must be signed in to change notification settings - Fork 60
fix: handle missing FastAPI request client #116
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -111,10 +111,14 @@ def get_method(self, request: starlette.requests.Request): | |||||
| return request.method | ||||||
|
|
||||||
| def get_remote_ip(self, request: starlette.requests.Request): | ||||||
| return request.client.host | ||||||
| if request.client: | ||||||
| return request.client.host | ||||||
| return json_logging.EMPTY_VALUE | ||||||
|
|
||||||
| def get_remote_port(self, request: starlette.requests.Request): | ||||||
| return request.client.port | ||||||
| if request.client: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to PEP 8, when testing whether a variable that defaults to
Suggested change
References
|
||||||
| return request.client.port | ||||||
| return json_logging.EMPTY_VALUE | ||||||
|
|
||||||
|
|
||||||
| class FastAPIResponseInfoExtractor(BaseResponseInfoExtractor): | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to PEP 8, when testing whether a variable that defaults to
Nonewas set to some other value, you should explicitly compare it usingis not Nonerather than relying on truthiness. This is especially important for objects that are containers (likeNamedTuple/tuplewhichrequest.clientis), as they could potentially evaluate toFalsein a boolean context if empty.References