villebro commented on a change in pull request #14742:
URL: https://github.com/apache/superset/pull/14742#discussion_r636698381
##########
File path: tests/tasks/async_queries_tests.py
##########
@@ -202,3 +203,29 @@ def test_soft_timeout_load_explore_json_into_cache(
ensure_user_is_set.side_effect = SoftTimeLimitExceeded()
load_explore_json_into_cache(job_metadata, form_data)
ensure_user_is_set.assert_called_once_with(user.id, "error",
errors=errors)
+
+ def test_ensure_user_is_set(self):
+ g_user_is_set = hasattr(g, "user")
+ original_g_user = g.user if g_user_is_set else None
+
+ if g_user_is_set:
+ del g.user
+
+ self.assertFalse(hasattr(g, "user"))
+ ensure_user_is_set(1)
+ self.assertTrue(hasattr(g, "user"))
+ self.assertFalse(g.user.is_anonymous)
+ self.assertEqual("1", g.user.get_id())
+
+ del g.user
+
+ self.assertFalse(hasattr(g, "user"))
+ ensure_user_is_set(None)
+ self.assertTrue(hasattr(g, "user"))
+ self.assertTrue(g.user.is_anonymous)
+ self.assertEqual(None, g.user.get_id())
+
+ if g_user_is_set:
+ g.user = original_g_user
+ else:
+ del g.user
Review comment:
In reference to the above comment, should we add a test case for cases
where `g.user` is set and see what `g.user` is after calling
`ensure_user_is_set`?
##########
File path: superset/tasks/async_queries.py
##########
@@ -43,6 +43,8 @@ def ensure_user_is_set(user_id: Optional[int]) -> None:
user_is_set = hasattr(g, "user") and g.user is not None
if not user_is_set and user_id is not None:
g.user = security_manager.get_user_by_id(user_id)
+ else:
+ g.user = security_manager.get_anonymous_user()
Review comment:
Wouldn't this set `g.user` to anonymous is `user_is_set`? It appears we
should make this `elif not user_is_set:`?
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]