mirror of
https://github.com/AJaySi/ALwrity.git
synced 2026-04-25 00:45:54 +03:00
[PR #432] Use shared multi-tenant get_db dependency across content-strategy endpoints #737
Labels
No labels
AI Content Agents
AI Content Strategy
AI Content planning
AI Marketing Tools
AI SEO
AI personalization
AI writer
ALwrity Copi-lot
Alwrity web search
Anthropic
DeepSeek
Gemini AI
Integration
LLM
OnBoarding
OnBoarding
RAG knowledgebase Memory
bug
documentation
enhancement
good first issue
help wanted
invalid
openai
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ALwrity#737
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/AJaySi/ALwrity/pull/432
Author: @AJaySi
Created: 3/12/2026
Status: 🔄 Open
Base:
main← Head:codex/refactor-db-access-in-content-strategy📝 Commits (1)
a9252edUse shared multi-tenant DB dependency in strategy endpoints📊 Changes
6 files changed (+168 additions, -47 deletions)
View changed files
📝
backend/api/content_planning/api/content_strategy/endpoints/ai_generation_endpoints.py(+7 -9)📝
backend/api/content_planning/api/content_strategy/endpoints/analytics_endpoints.py(+2 -10)📝
backend/api/content_planning/api/content_strategy/endpoints/autofill_endpoints.py(+7 -9)📝
backend/api/content_planning/api/content_strategy/endpoints/streaming_endpoints.py(+1 -9)📝
backend/api/content_planning/api/content_strategy/endpoints/utility_endpoints.py(+2 -10)➕
backend/tests/api/content_planning/content_strategy/endpoints/test_shared_get_db_dependency.py(+149 -0)📄 Description
Motivation
get_db()helpers calledget_db_session()without an authenticated user, which returnsNonein multi-tenant mode and can break DB access.services.database.get_db, so endpoints should rely on that shared dependency.get_dbcan resolve a tenant-specific engine/session.Description
get_db()wrappers that usedget_db_session()from the following modules and switched them to importget_dbfromservices.database:utility_endpoints.py,analytics_endpoints.py,autofill_endpoints.py,streaming_endpoints.py, andai_generation_endpoints.py.Depends(get_current_user)to DB-backed routes that previously lacked explicit authentication parameters so tenant context is available toget_db(notably inautofill_endpointsand core AI generation routes).db.close()handling in endpoint-local wrappers by relying on the sharedget_dbdependency to manage session lifecycle.backend/tests/api/content_planning/content_strategy/endpoints/test_shared_get_db_dependency.pythat overrideget_dband auth dependencies and assert that injected/fake services receive a non-null DB session for one representative endpoint per modified module.Testing
pytest -q backend/tests/api/content_planning/content_strategy/endpoints/test_shared_get_db_dependency.pyand verified all tests passed:5 passed.FastAPITestClient, overrideget_dbwith aFakeDBSession, override auth dependencies, and monkeypatch endpoint services to assertdbis non-null and responses return a successful status.Codex Task
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.