kbohra commented on code in PR #62919:
URL: https://github.com/apache/airflow/pull/62919#discussion_r2890525698


##########
providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py:
##########
@@ -292,16 +292,26 @@ def session(self):
 
     @cachedmethod(lambda self: self.cache, key=lambda _, token: 
int(token["sub"]))
     def deserialize_user(self, token: dict[str, Any]) -> User:
+        user_id = int(token["sub"])
         try:
-            return self.session.scalars(select(User).where(User.id == 
int(token["sub"]))).one()
+            return self.session.scalars(select(User).where(User.id == 
user_id)).one()
         except NoResultFound:
             raise ValueError(f"User with id {token['sub']} not found")
         except SQLAlchemyError:
             # Discard the poisoned scoped session so the next request gets a
             # fresh connection from the pool instead of a PendingRollbackError.
             with suppress(Exception):
                 self.session.remove()
-            raise
+            try:

Review Comment:
   Done, tests passed . 
   
   ```
   
providers/fab/tests/unit/fab/auth_manager/test_fab_auth_manager.py::TestDeserializeUserSessionCleanup::test_db_error_calls_session_remove[operational_error]
 PASSED                                                                         
                             [ 16%]
   
providers/fab/tests/unit/fab/auth_manager/test_fab_auth_manager.py::TestDeserializeUserSessionCleanup::test_db_error_calls_session_remove[pending_rollback_error]
 PASSED                                                                         
                        [ 33%]
   
providers/fab/tests/unit/fab/auth_manager/test_fab_auth_manager.py::TestDeserializeUserSessionCleanup::test_db_error_propagates_when_session_remove_raises
 PASSED                                                                         
                               [ 50%]
   
providers/fab/tests/unit/fab/auth_manager/test_fab_auth_manager.py::TestDeserializeUserSessionCleanup::test_db_error_retries_once_and_recovers
 PASSED                                                                         
                                           [ 66%]
   
providers/fab/tests/unit/fab/auth_manager/test_fab_auth_manager.py::TestFabAuthManagerSessionCleanup::test_session_cleanup_middleware_on_wsgi_route
 PASSED                                                                         
                                      [ 83%]
   
providers/fab/tests/unit/fab/auth_manager/test_fab_auth_manager.py::TestFabAuthManagerSessionCleanupErrorHandling::test_session_remove_db_error_does_not_propagate
 PASSED                                                                         
                       [100%]
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to