From a57a8e54fa5d4d802a90528dd01713d659bf443f Mon Sep 17 00:00:00 2001 From: Rahul Rao Date: Tue, 14 Jul 2026 22:37:37 +0530 Subject: [PATCH] fix: use None sentinel instead of mutable OAuthFlowsModel() default in OAuth2.__init__ --- fastapi/security/oauth2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastapi/security/oauth2.py b/fastapi/security/oauth2.py index 3fd9e41eb..6bee873fd 100644 --- a/fastapi/security/oauth2.py +++ b/fastapi/security/oauth2.py @@ -350,7 +350,7 @@ class OAuth2(SecurityBase): The dictionary of OAuth2 flows. """ ), - ] = OAuthFlowsModel(), + ] = None, scheme_name: Annotated[ str | None, Doc( @@ -392,6 +392,8 @@ class OAuth2(SecurityBase): ), ] = True, ): + if flows is None: + flows = OAuthFlowsModel() self.model = OAuth2Model( flows=cast(OAuthFlowsModel, flows), description=description )