#DB Session not supplied, what did I do wrong?

1 messages · Page 1 of 1 (latest)

calm crow
#

I must have done something wrong, imagine that.
First this appears to not work:

if TYPE_CHECKING: from sqlalchemy.ext.asyncio import AsyncSession

but this does
#if TYPE_CHECKING: from sqlalchemy.ext.asyncio import AsyncSession

This is probably related to the fact that when I run the code, I'm asked to supply a value for db_session in the OpenAPI interface.
Here is the code for that:

class ExerciseRepository(SQLAlchemyAsyncRepository[Exercise]):
    """Exercise repository."""

    model_type = Exercise

async def provide_exercise_repo(db_session: AsyncSession) -> ExerciseRepository:
    """This provides a simple example demonstrating how to override the join options
    for the repository."""
    return ExerciseRepository(session=db_session)


class ExerciseController(Controller):
    path = '/exercise'
    dependencies = {
        'exercise_repo': Provide(provide_exercise_repo),
    }
    exercise_controller_tag = ['Exercise - CRUD']

I did have this working with a different model in a different controller.
I think that this is pretty much the same as the code found here:
https://docs.litestar.dev/latest/tutorials/repository-tutorial/03-repository-controller.html

Any thoughts on what I screwed up?

slim solarBOT
#
Notes for DB Session not supplied, what did I do wrong?
At your assistance

@calm crow

No Response?

If no response in a reasonable time, ping @Member.

Closing

To close, type !solve or byte solve.

MCVE

Please include an MCVE so that we can reproduce your issue locally.