one-zero-eight / rooms

API of InNoHassle Rooms
MIT License
2 stars 0 forks source link

Async psycopg driver throws errors when sqlalchemy lazy loads relationships #20

Closed Makcal closed 5 months ago

Makcal commented 8 months ago

Describe the bug

Async psycopg driver throws errors (greenlet has not been spawned) when sqlalchemy lazy loads relationships.

Possible affect:

I suppose that due to sa_relationship_kwargs={"lazy": "joined"} used now large and redundant amounts of data are loaded through relations (i.e. user -> invitation -> other user -> other invitation -> ...).

Known solutions:

  1. Make DB connections synchronous
  2. Prevent relationships to be lazy loaded by loading it manually or at the moment when a main object is loaded The very last option is chosen

Reproduction

  1. Remove sa_relationship_kwargs={"lazy": "joined"} from relationship definitions
  2. Run tests

Screenshots / Additional context

Some info

Makcal commented 8 months ago

Should be rechecked after https://github.com/one-zero-eight/InNoHassle-Rooms/commit/e9bdf6672f85f7b195aeb1b5113599a8fae5b829

Makcal commented 5 months ago

All relationships are removed out of harm's way. Honestly, they are nightmare. I don't know how to make them work properly (without tons of extra methods or attributes) with asynchronous DB drivers. Solved in e6fa5bb

Makcal commented 5 months ago

Maybe use joinedload()/selectinload() to request only specified relationships (reference). Maybe in future...