Skip to content

Add user and request context for admin class#125

Merged
vsdudakov merged 2 commits intomainfrom
enhancement/user_request_context
Feb 23, 2026
Merged

Add user and request context for admin class#125
vsdudakov merged 2 commits intomainfrom
enhancement/user_request_context

Conversation

@vsdudakov
Copy link
Copy Markdown
Owner

References

Summary

Are there any open tasks or blockers?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds request and user context support to admin model classes, allowing admin methods to access the current request object and authenticated user within their implementation. The feature uses Python's ContextVar to maintain thread-safe, async-context-isolated storage of request and user objects.

Changes:

  • Added request and user properties to BaseModelAdmin using ContextVar for async-safe context isolation
  • Updated all API service methods to bind request and user context to admin models before executing operations
  • Extended framework integrations (Flask, FastAPI, Django) to pass request objects through to the service layer

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
fastadmin/models/base.py Added _request_context and _user_context ContextVar attributes, request/user properties, and set_context() method to BaseModelAdmin
fastadmin/api/service.py Added _bind_admin_context() helper and _get_authenticated_user() method; updated all API methods to accept and bind request/user context
fastadmin/models/helpers.py Updated generate_models_schema() to accept and propagate request/user context to admin models and inlines
fastadmin/api/frameworks/flask/api.py Updated all API endpoints to pass request=request to service methods
fastadmin/api/frameworks/fastapi/api.py Updated all API endpoints to pass request=request to service methods
fastadmin/api/frameworks/django/app/api.py Updated all API endpoints to pass request=request to service methods
tests/models/test_base.py Added test for request/user context get/set functionality
tests/api/test_service.py Added test verifying context binding in the list operation
tests/api/frameworks/flask/test_app.py Updated dashboard widget test to verify request parameter passing
tests/api/frameworks/fastapi/test_app.py Updated dashboard widget test to verify request parameter passing
tests/api/frameworks/django/test_app.py Updated dashboard widget test to verify request parameter passing
docs/index.html Added documentation and example code demonstrating context usage in admin methods
docs/build.py Updated version changelog and added documentation content for the new feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fastadmin/api/service.py Outdated
Comment thread fastadmin/api/service.py
@vsdudakov vsdudakov merged commit 1e4e221 into main Feb 23, 2026
@vsdudakov vsdudakov deleted the enhancement/user_request_context branch February 23, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants