@@ -486,7 +486,10 @@ def find_installation(
486486 installed_at = row [23 ],
487487 )
488488
489- if user_id is not None :
489+ has_user_installation = user_id is not None and installation is not None
490+ no_bot_token_installation = installation is not None and installation .bot_token is None
491+ should_find_bot_installation = has_user_installation or no_bot_token_installation
492+ if should_find_bot_installation :
490493 # Retrieve the latest bot token, just in case
491494 # See also: https://github.com/slackapi/bolt-python/issues/664
492495 cur = conn .execute (
@@ -514,12 +517,13 @@ def find_installation(
514517 [self .client_id , enterprise_id or "" , team_id ],
515518 )
516519 row = cur .fetchone ()
517- installation .bot_token = row [0 ]
518- installation .bot_id = row [1 ]
519- installation .bot_user_id = row [2 ]
520- installation .bot_scopes = row [3 ]
521- installation .bot_refresh_token = row [4 ]
522- installation .bot_token_expires_at = row [5 ]
520+ if row is not None :
521+ installation .bot_token = row [0 ]
522+ installation .bot_id = row [1 ]
523+ installation .bot_user_id = row [2 ]
524+ installation .bot_scopes = row [3 ]
525+ installation .bot_refresh_token = row [4 ]
526+ installation .bot_token_expires_at = row [5 ]
523527
524528 return installation
525529 return None
0 commit comments