jonra1993 / fastapi-alembic-sqlmodel-async

This is a project template which uses FastAPI, Pydantic 2.0, Alembic and async SQLModel as ORM. It shows a complete async CRUD using authentication and role base access control.
MIT License
879 stars 143 forks source link

fix sqlalchemy relations #1

Closed fozt closed 2 years ago

fozt commented 2 years ago

When installing dependencies, version sqlaclhemy==1.4.36 is installed. It contains a bug that makes relationships to other tables not work. Even sa_relationship_kwargs={"lazy": "selectin"} parameter doesn't help. On version 1.4.35 this error disappears

How to reproduce the error with the old poetry.lock and pyproject.toml files:

  1. Run commands
    docker rm -f traefik-proxy fastapi_server nginx database
    rm -rf db_docker
    docker-compose up-build
    docker-compose exec fastapi_server python app/initial_data.py
  2. Go to http://fastapi.localhost/docs and authorize username: admin@admin.com password: admin
  3. Run POST method /api/v1/team with any parameters
  4. Run GET method /api/v1/team/{team_id} with parameter team_id=1

Translated with www.DeepL.com/Translator (free version)

fozt commented 2 years ago

Created a repository to demonstrate the error

jonra1993 commented 2 years ago

Hello, @fozt thanks for reporting this bug and sharing your PR. The bug is also mentioned here https://github.com/tiangolo/sqlmodel/issues/315