Add tenant-id integration and improve asyncio handling#1
Merged
faizanazim11 merged 5 commits intomainfrom Mar 15, 2025
Merged
Conversation
Added tenant-id integration. as of now taking default implementation to fetch tenant-id from cookies of fastapi.
… cancel outstanding tasks
There was a problem hiding this comment.
Pull Request Overview
This PR updates the integration to use tenant_id instead of project_id and improves the asyncio event loop handling to cancel outstanding tasks more robustly. The key changes include:
- Replacing project_id with tenant_id throughout the codebase.
- Updating asyncio handling to use asyncio.get_running_loop along with improved cancellation of tasks.
- Bumping the package version and updating dependency revisions (e.g. ruff) for enhanced performance and integration.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| sql_db_utils/declarative_utils.py | Renamed project_id to tenant_id and updated synchronous asyncio logic. |
| sql_db_utils/asyncio/declarative_utils.py | Renamed project_id to tenant_id and improved asynchronous cancellation. |
| sql_db_utils/version.py | Updated version from 1.0.0 to 1.0.1. |
| sql_db_utils/asyncio/session_management.py | Renamed project_id to tenant_id and updated type annotations. |
| sql_db_utils/session_management.py | Renamed project_id to tenant_id and updated caching and engine logic. |
| sql_db_utils/constants.py | Updated enum base classes to use StrEnum directly. |
| .pre-commit-config.yaml | Updated ruff revision to a newer version. |
| sql_db_utils/config.py | Removed Redis config in all export. |
Comments suppressed due to low confidence (1)
sql_db_utils/asyncio/declarative_utils.py:98
- Calling loop.stop() within _get_declarative_module may stop the event loop unexpectedly, affecting other asynchronous operations. Consider removing or refactoring this call to manage loop termination in a more controlled manner.
loop.call_soon_threadsafe(loop.stop)
…nding asyncio tasks
There was a problem hiding this comment.
Pull Request Overview
This PR refactors existing code to replace the use of "project_id" with "tenant_id" for multi-tenant support and improves asyncio event loop handling for graceful cancellation of pending tasks. Key changes include:
- Renaming function parameters and variables from project_id to tenant_id across multiple modules.
- Updating asyncio shutdown procedures to use get_running_loop() and properly cancel outstanding tasks.
- Adjusting configuration and session management code to align with the tenant-id logic.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| sql_db_utils/asyncio/declarative_utils.py | Refactored tenant-id usage and updated asynchronous cancellation logic. |
| sql_db_utils/declarative_utils.py | Similar tenant-id refactor and updated cancellation logic in synchronous context. |
| sql_db_utils/version.py | Version bump from 1.0.0 to 1.0.1. |
| sql_db_utils/asyncio/session_management.py | Replaced project_id with tenant_id and updated cookie parameter. |
| sql_db_utils/session_management.py | Similar tenant-id updates in synchronous session management. |
| sql_db_utils/constants.py | Minor adjustment to enum class declaration. |
| .pre-commit-config.yaml | Updated ruff-pre-commit version. |
| sql_db_utils/config.py | Removed RedisConfig from public exports. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce tenant-id integration by fetching it from cookies in FastAPI. Update asyncio event loop handling to use
get_running_loopand cancel outstanding tasks for better performance.