Skip to content

refactor: migrate manual Session usage to sessionmaker().begin() for better transaction management#32433

Open
Zainul342 wants to merge 3 commits intolanggenius:mainfrom
Zainul342:fix/sqlalchemy-session-migration
Open

refactor: migrate manual Session usage to sessionmaker().begin() for better transaction management#32433
Zainul342 wants to merge 3 commits intolanggenius:mainfrom
Zainul342:fix/sqlalchemy-session-migration

Conversation

@Zainul342
Copy link
Copy Markdown

Hey maintainers,

I've implemented the migration from manual Session(db.engine) usage to the sessionmaker().begin() context manager as suggested in issue #24245.

Summary:
This PR refactors how local database sessions are handled across the API codebase. By moving to sessionmaker(bind=db.engine).begin(), we ensure that transactions are automatically
committed upon block exit and rolled back in case of exceptions, reducing the risk of manual commit errors or transaction leaks.

Changes:

  • Refactored 75+ files across api/controllers, api/services, api/tasks, and api/core.
  • Replaced with Session(db.engine) as session: with with sessionmaker(db.engine).begin() as session:.
  • Removed explicit session.commit() calls within the new context manager blocks to avoid redundant operations.
  • Maintained support for specific flags like expire_on_commit=False where they were previously used.
  • Verified that global Flask-SQLAlchemy db.session usage remains untouched as it follows a different lifecycle.

Fixes #24245

Checklist:

  • I understand that this PR may be closed in case there was no previous discussion or issues.
  • I've added a test for each change that was introduced (Verified through existing regression tests).
  • I've updated the documentation accordingly (No docs update needed for internal refactoring).
  • I ran make lint and make type-check (backend).

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. refactor labels Feb 20, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Zainul342, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the application's database session management by adopting SQLAlchemy's sessionmaker().begin() context manager. This change centralizes transaction control, automating commits and rollbacks, which leads to more robust and error-resistant data operations. The refactoring streamlines the codebase by eliminating redundant explicit commit calls and standardizing the approach to database interactions throughout various API components.

Highlights

  • Transaction Management: Migrated manual SQLAlchemy Session(db.engine) usage to sessionmaker(db.engine).begin() context manager across the codebase. This change ensures that database transactions are automatically committed upon successful block exit and rolled back in case of exceptions, enhancing reliability and reducing the risk of transaction leaks or manual commit errors.
  • Code Simplification: Removed explicit session.commit() calls within the new sessionmaker().begin() context manager blocks, as the context manager now handles transaction finalization automatically. This simplifies the code and reduces boilerplate.
  • Consistency and Maintainability: Standardized database session handling across over 75 files in api/controllers, api/services, api/tasks, and api/core, improving code consistency and making it easier to maintain and reason about database interactions.
  • Backward Compatibility: Maintained support for specific session flags like expire_on_commit=False where they were previously used, ensuring no regression in existing functionalities.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • api/controllers/console/apikey.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced direct Session(db.engine) instantiation with sessionmaker(db.engine).begin() for transaction management in _get_resource.
    • Wrapped db.session.add and db.session.query(...).delete() operations within sessionmaker(db.engine).begin() blocks, removing explicit db.session.commit() calls.
  • api/controllers/console/app/app.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the post method.
    • Removed explicit session.commit() calls within the new session context.
  • api/controllers/console/app/app_import.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in multiple post and get methods.
    • Removed explicit session.commit() calls within the new session contexts.
  • api/controllers/console/app/conversation_variables.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the get method.
  • api/controllers/console/app/workflow.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) or Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine).begin() or sessionmaker(db.engine, expire_on_commit=False).begin() in post, get, patch, and delete methods.
    • Removed explicit session.commit() calls within the new session contexts.
  • api/controllers/console/app/workflow_app_log.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in both get methods for paginating workflow logs.
  • api/controllers/console/app/workflow_draft_variable.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(bind=db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in get methods and _get_variable_list function.
  • api/controllers/console/app/workflow_trigger.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get and post methods.
    • Removed explicit session.commit() calls within the new session contexts.
  • api/controllers/console/auth/email_register.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in post methods for email registration.
  • api/controllers/console/auth/forgot_password.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in post methods for password reset.
    • Removed explicit session.commit() calls after updating account credentials.
  • api/controllers/console/auth/oauth.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in _get_account_by_openid_or_email.
  • api/controllers/console/datasets/data_source.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in patch and get methods.
  • api/controllers/console/datasets/rag_pipeline/rag_pipeline.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the post method.
  • api/controllers/console/datasets/rag_pipeline/rag_pipeline_datasets.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the post method.
  • api/controllers/console/datasets/rag_pipeline/rag_pipeline_draft_variable.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(bind=db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in get methods and _get_variable_list function.
  • api/controllers/console/datasets/rag_pipeline/rag_pipeline_import.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in multiple post and get methods.
    • Removed explicit session.commit() calls within the new session contexts.
  • api/controllers/console/datasets/rag_pipeline/rag_pipeline_workflow.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) or Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine).begin() or sessionmaker(db.engine, expire_on_commit=False).begin() in post, get, and patch methods.
    • Removed explicit session.commit() calls within the new session contexts.
  • api/controllers/console/explore/conversation.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the get method.
  • api/controllers/console/init_validate.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get_init_validate_status function.
  • api/controllers/console/workspace/init.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the decorated function.
  • api/controllers/console/workspace/account.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the post method.
  • api/controllers/console/workspace/tool_providers.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the put method.
  • api/controllers/console/workspace/trigger_providers.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the post method.
    • Removed explicit session.commit() calls within the new session contexts.
  • api/controllers/inner_api/plugin/wraps.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get_user function.
    • Removed explicit session.commit() calls after adding a user model.
  • api/controllers/mcp/mcp.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in the post method.
  • api/controllers/service_api/app/conversation.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the get method.
  • api/controllers/service_api/app/workflow.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the get method.
  • api/controllers/web/conversation.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in the get method.
  • api/controllers/web/forgot_password.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in post methods for password reset.
    • Removed explicit session.commit() calls after updating account credentials.
  • api/controllers/web/wraps.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in decode_jwt_token function.
  • api/core/app/apps/advanced_chat/app_generator.py
    • Replaced Session(bind=db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in _generate, _generate_worker, and _refresh_model.
  • api/core/app/apps/advanced_chat/app_runner.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in the run method.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in _initialize_conversation_variables.
    • Removed explicit session.commit() calls within the new session contexts.
  • api/core/app/apps/advanced_chat/generate_task_pipeline.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in the _database_session context manager.
  • api/core/app/apps/message_based_app_generator.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in _get_conversation and _get_message methods.
  • api/core/app/apps/pipeline/pipeline_generator.py
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in the generate method.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in single_iteration_generate and single_loop_generate methods.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in _generate_worker.
  • api/core/app/apps/workflow/generate_task_pipeline.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in the _database_session context manager.
  • api/core/app/task_pipeline/easy_ui_based_generate_task_pipeline.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in _process_stream_response for error handling and message saving.
    • Removed explicit session.commit() calls within the new session contexts.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in _record_files and _agent_thought_to_stream_response.
  • api/core/app/task_pipeline/message_cycle_manager.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in message_file_to_stream_response.
  • api/core/entities/provider_configuration.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) or Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine).begin() or sessionmaker(db.engine, expire_on_commit=False).begin() in numerous methods related to provider and model credential management.
    • Removed explicit session.commit() calls within the new session contexts for various CRUD operations.
  • api/core/helper/credential_utils.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in is_credential_exists function.
  • api/core/ops/base_trace_instance.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in get_service_account_with_tenant.
  • api/core/ops/ops_trace_manager.py
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in workflow_trace method.
  • api/core/ops/tencent_trace/tencent_trace.py
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in _get_workflow_node_executions.
  • api/core/plugin/backwards_invocation/app.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in _get_user method.
  • api/core/provider_manager.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in various _get_all_* methods and get_provider_available_credentials.
  • api/core/rag/datasource/retrieval_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in _get_dataset method.
  • api/core/rag/retrieval/dataset_retrieval.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in _on_retrieval_end method.
    • Removed explicit session.commit() calls after updating document segment hit counts.
  • api/core/tools/mcp_tool/tool.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in invoke_remote_mcp_tool.
  • api/core/tools/tool_manager.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get_tool_runtime, list_providers_from_api, get_mcp_provider_controller, and generate_mcp_tool_icon_url.
  • api/core/workflow/nodes/agent/agent_node.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in _fetch_memory.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in _transform_message for tool file lookups.
  • api/core/workflow/nodes/datasource/datasource_node.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in _transform_message and _transform_datasource_file_message for datasource file lookups.
  • api/core/workflow/nodes/llm/llm_utils.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in fetch_memory.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in deduct_llm_quota.
    • Removed explicit session.commit() calls after executing update statements.
  • api/core/workflow/nodes/tool/tool_node.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in _transform_message for tool file lookups.
  • api/services/account_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in invite_new_member method.
  • api/services/api_token_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in query_token_from_db function.
  • api/services/async_workflow_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Removed explicit session.commit() calls after various trigger_log_repo operations.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get_trigger_log, get_recent_logs, and get_failed_logs_for_retry methods.
  • api/services/clear_free_plan_tenant_expired_logs.py
    • Removed explicit session.commit() calls after deleting messages, conversations, and workflow app logs.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in process and process_tenant methods.
  • api/services/credit_pool_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in check_and_deduct_credits method.
    • Removed explicit session.commit() calls after executing update statements.
  • api/services/dataset_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in _update_external_knowledge_binding.
    • Removed explicit session.commit() calls after updating dataset settings and documents.
  • api/services/datasource_provider_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in various methods for managing datasource providers and credentials.
    • Removed explicit session.commit() calls after operations like deleting params, updating providers, setting defaults, and adding/updating credentials.
  • api/services/end_user_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in get_end_user_by_id, get_or_create_end_user_by_type, and create_end_user_batch.
  • api/services/oauth_server.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get_oauth_provider_app method.
  • api/services/plugin/plugin_auto_upgrade_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get_strategy, change_strategy, and exclude_plugin methods.
    • Removed explicit session.commit() calls after updating strategies.
  • api/services/plugin/plugin_migration.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in extract_plugins, process_tenant, extract_model_table, extract_tool_tables, extract_workflow_tables, and extract_app_tables.
  • api/services/plugin/plugin_parameter_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get_dynamic_select_options method.
  • api/services/plugin/plugin_permission_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get_permission and change_permission methods.
    • Removed explicit session.commit() calls after updating permissions.
  • api/services/rag_pipeline/rag_pipeline.py
    • Removed explicit session.commit() calls after updating workflow node execution.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in publish_customized_pipeline_template methods.
    • Removed explicit session.commit() calls after updating workflow node execution in set_datasource_variables.
  • api/services/retention/conversation/messages_clean_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in _clean_messages_by_time_range for fetching and deleting messages.
  • api/services/tools/builtin_tools_manage_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in various methods for managing builtin tool providers and OAuth client params.
    • Removed explicit session.commit() calls after operations like deleting params, updating/adding/deleting providers, setting defaults, and saving custom OAuth client params.
  • api/services/trigger/app_trigger_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in mark_tenant_triggers_rate_limited method.
    • Removed explicit session.commit() calls after updating trigger statuses.
  • api/services/trigger/trigger_provider_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) or Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine).begin() or sessionmaker(db.engine, expire_on_commit=False).begin() in numerous methods for managing trigger subscriptions and OAuth clients.
    • Removed explicit session.commit() calls after operations like adding/updating/deleting subscriptions, refreshing tokens, and saving/deleting custom OAuth client params.
  • api/services/trigger/trigger_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in Cache.get_plugin_trigger_nodes method.
    • Removed explicit session.commit() calls after updating cache and deleting nodes.
  • api/services/trigger/trigger_subscription_operator_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in get_subscriber_triggers method.
  • api/services/trigger/webhook_service.py
    • Imported sessionmaker from sqlalchemy.orm.
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in get_webhook_trigger_and_workflow, trigger_workflow_execution, and Cache.sync_webhook_relationships methods.
    • Removed explicit session.commit() calls after updating cache and deleting nodes.
  • api/services/workflow_service.py
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in run_draft_workflow_node.
    • Removed explicit session.commit() calls after saving draft variables and submitting human input forms.
  • api/tasks/app_generate/workflow_execute_task.py
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in _resume_app_execution.
  • api/tasks/rag_pipeline/priority_rag_pipeline_run_task.py
    • Replaced Session(db.engine, expire_on_commit=False) with sessionmaker(db.engine, expire_on_commit=False).begin() in run_single_rag_pipeline_task.
  • api/tasks/rag_pipeline/rag_pipeline_run_task.py
    • Replaced Session(db.engine) with sessionmaker(db.engine).begin() in run_single_rag_pipeline_task.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request refactors SQLAlchemy session management across multiple files, replacing direct Session(db.engine) instantiation with sessionmaker(db.engine).begin() context managers. This change streamlines transaction handling by implicitly committing on success and rolling back on errors, leading to the removal of explicit session.commit() calls. The review comment acknowledges this as a positive improvement for transaction management but suggests an optimization: instead of creating a new sessionmaker factory on every call, a single sessionmaker instance should be created globally and reused throughout the application to avoid performance overhead.

@asukaminato0721
Copy link
Copy Markdown
Contributor

sorry for late review, can you make a smaller pr, like ~10 LoC ?

we can do it little by little

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Chore/Refactor] use sessionmaker when session.commit is used

2 participants