Skip to content

Update DB config #30

Merged
Jungminchae merged 3 commits intomainfrom
db/config
Oct 28, 2025
Merged

Update DB config #30
Jungminchae merged 3 commits intomainfrom
db/config

Conversation

@Jungminchae
Copy link
Member

  • to put session, engine config, made parameter for seesion, engine configuration

@gemini-code-assist
Copy link

Summary of Changes

Hello @Jungminchae, 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 introduces significant improvements to the application's configuration and database interaction layers. It modernizes environment variable management by migrating to pydantic-settings, which streamlines how application settings are defined and loaded. Concurrently, it enhances the database module by enabling more granular control over SQLAlchemy's engine and session configurations, allowing developers to fine-tune database behavior. These changes contribute to a more robust and flexible foundation for the project.

Highlights

  • Configuration Management Refactor: The application's configuration handling has been updated to use pydantic-settings instead of python-decouple for loading environment variables, providing a more integrated and type-safe approach to settings.
  • Enhanced Database Configuration: The AsyncDB class now accepts explicit engine_config and session_config parameters, allowing for greater flexibility and customization when initializing SQLAlchemy's asynchronous engine and session makers.
  • Project Version Update: The project version in pyproject.toml has been incremented from 0.5.2 to 0.6.0.
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.

@Jungminchae Jungminchae merged commit 81da6fe into main Oct 28, 2025
1 check passed
@Jungminchae Jungminchae deleted the db/config branch October 28, 2025 05:11
Copy link

@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

This pull request updates the database configuration to allow passing engine and session parameters, and switches from python-decouple to pydantic-settings for configuration management. My review found a critical issue in the settings template file where the switch to pydantic-settings was incomplete, which will cause the application to crash. I also found a high-severity issue in the database configuration class related to the use of mutable default arguments, which could lead to subtle bugs. I've provided suggestions to fix both issues.

Comment on lines 8 to 9
DEBUG: bool = config("DEBUG", cast=bool, default=True)
OPENAPI_URL: str | None = "/openapi.json" if DEBUG else None

Choose a reason for hiding this comment

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

critical

These lines will cause NameError exceptions at runtime.

  1. On line 8, the config function is no longer defined since python-decouple was removed. With pydantic-settings, you can just declare the attribute with a default value.
  2. On line 9, DEBUG is not a defined variable in the class scope, so it cannot be used to define OPENAPI_URL.

To fix this and preserve the intended logic, you should use a Pydantic model_validator. This requires importing model_validator from pydantic.

Here's an example of the full implementation:

from pathlib import Path
from zoneinfo import ZoneInfo
from pydantic import model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict


class AppSettings(BaseSettings):
    model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
    DEBUG: bool = True
    OPENAPI_URL: str | None = None
    API_PREFIX: str = "/api/v1"
    # ... other settings

    @model_validator(mode='after')
    def set_openapi_url(self) -> 'AppSettings':
        if self.DEBUG:
            self.OPENAPI_URL = "/openapi.json"
        return self

The suggested code below provides a minimal fix to make the template parsable, but I strongly recommend implementing the validator pattern for correct behavior.

    DEBUG: bool = True
    OPENAPI_URL: str | None = "/openapi.json"

Comment on lines +34 to +38
def __init__(self, db_url: str, meta: MetaData = None, engine_config: dict = {}, session_config: dict = {}) -> None:
self.db_url = db_url
self.meta = meta
self.__engine = create_async_engine(db_url)
self.__async_session = async_sessionmaker(self.__engine, **kwargs)
self.__engine = create_async_engine(db_url, **engine_config)
self.__async_session = async_sessionmaker(self.__engine, **session_config)

Choose a reason for hiding this comment

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

high

Using mutable default arguments like {} for engine_config and session_config can lead to unexpected behavior. The same dictionary object will be reused across different calls to the constructor if no value is provided, which can cause side effects if the dictionary is modified in-place. The recommended practice is to use None as the default and create a new dictionary inside the method if one isn't provided.

Suggested change
def __init__(self, db_url: str, meta: MetaData = None, engine_config: dict = {}, session_config: dict = {}) -> None:
self.db_url = db_url
self.meta = meta
self.__engine = create_async_engine(db_url)
self.__async_session = async_sessionmaker(self.__engine, **kwargs)
self.__engine = create_async_engine(db_url, **engine_config)
self.__async_session = async_sessionmaker(self.__engine, **session_config)
def __init__(self, db_url: str, meta: MetaData = None, engine_config: dict | None = None, session_config: dict | None = None) -> None:
self.db_url = db_url
self.meta = meta
self.__engine = create_async_engine(db_url, **(engine_config or {}))
self.__async_session = async_sessionmaker(self.__engine, **(session_config or {}))

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.

1 participant