Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Addresses feedback from PR #40 regarding the lazy import of models inside the init_db() function, which violates the convention of keeping imports at module top-level.

Changes

  • Moved model registration to package level: Import models in app/__init__.py to ensure SQLAlchemy metadata registration occurs at package import time
  • Removed lazy import: Cleaned up init_db() by removing the internal from app import models statement

Before

# app/database.py
async def init_db() -> None:
    """Crea las tablas si no existen (útil para desarrollo y tests)."""
    # Importación tardía para registrar modelos antes de create_all
    from app import models  # noqa: F401
    
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)

After

# app/__init__.py
from app import models  # noqa: F401

# app/database.py
async def init_db() -> None:
    """Crea las tablas si no existen (útil para desarrollo y tests)."""
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)

This eliminates the lazy import pattern while maintaining proper model registration and avoiding circular dependencies.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix issues based on feedback for hotfix/CI precommit Refactor: Move models import to package level to resolve lazy loading in init_db() Oct 30, 2025
Copilot AI requested a review from Neiland85 October 30, 2025 15:08
@Neiland85
Copy link
Owner

This PR has been overtaken by the 2025 architecture refactor.
Closing it with respect, but it is no longer part of the living codebase.

@Neiland85 Neiland85 closed this Dec 10, 2025
@Neiland85 Neiland85 deleted the copilot/sub-pr-40-9b72efdd-a8c7-443d-9179-14f8269ced5c branch December 10, 2025 16:51
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