File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 1+ ## 5.0.3
2+ - Fix for Potential n+1 query detected on AuthToken.user
3+
14## 5.0.2
25- Implement AUTO_REFRESH_MAX_TTL to limit total token lifetime when AUTO_REFRESH = True
36
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ def authenticate_credentials(self, token):
6060 msg = _ ('Invalid token.' )
6161 token = token .decode ("utf-8" )
6262 for auth_token in get_token_model ().objects .filter (
63- token_key = token [:CONSTANTS .TOKEN_KEY_LENGTH ]):
63+ token_key = token [:CONSTANTS .TOKEN_KEY_LENGTH ]). select_related ( 'user' ) :
6464 if self ._cleanup_token (auth_token ):
6565 continue
6666
Original file line number Diff line number Diff line change @@ -229,6 +229,19 @@ def test_update_token_key(self):
229229 auth_token .token_key ,
230230 )
231231
232+ def test_token_auth_n_plus_one (self ):
233+ self .assertEqual (AuthToken .objects .count (), 0 )
234+ _ , token = AuthToken .objects .create (self .user )
235+ rf = APIRequestFactory ()
236+ request = rf .get ('/' )
237+ request .META = {'HTTP_AUTHORIZATION' : f'Token { token } ' }
238+ with self .assertNumQueries (2 ):
239+ (self .user , auth_token ) = TokenAuthentication ().authenticate (request )
240+ self .assertEqual (
241+ token [:CONSTANTS .TOKEN_KEY_LENGTH ],
242+ auth_token .token_key ,
243+ )
244+
232245 def test_authorization_header_empty (self ):
233246 rf = APIRequestFactory ()
234247 request = rf .get ('/' )
You can’t perform that action at this time.
0 commit comments