GitHub user dosubot[bot] added a comment to the discussion: Multi-Tenant User 
management

<!-- Answer -->
Correct—add_form_query_rel_fields and edit_form_query_rel_fields are static and 
set at class definition time, so they can't access user context (g.user) or 
anything from the current request. This is a limitation of Flask AppBuilder's 
design: those hooks are not evaluated per-request, so dynamic filtering based 
on the logged-in user isn't possible there [source].

If you need per-user filtering (like showing only certain roles in the dropdown 
based on the current user), the supported way is to subclass FAB's RoleApi, 
override its list method, and apply your filtering logic using g.user. Then 
register your custom API in FLASK_APP_MUTATOR. This approach gives you full 
access to user context and works reliably for tenant-based filtering. There are 
no documented workarounds for injecting user context into those field hooks.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/e0f68223-63cb-4f6b-94c5-48b85baf6e4d?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/e0f68223-63cb-4f6b-94c5-48b85baf6e4d?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/e0f68223-63cb-4f6b-94c5-48b85baf6e4d?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/e0f68223-63cb-4f6b-94c5-48b85baf6e4d?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/e0f68223-63cb-4f6b-94c5-48b85baf6e4d?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/e0f68223-63cb-4f6b-94c5-48b85baf6e4d?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/e0f68223-63cb-4f6b-94c5-48b85baf6e4d?feedback_type=other)</sup>&nbsp;&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Sh
 are on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/33877)

GitHub link: 
https://github.com/apache/superset/discussions/33877#discussioncomment-13691095

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to