Replies: 2 comments
-
I ended up forking the repo and tweaking the usage of |
Beta Was this translation helpful? Give feedback.
-
Yes and no - GINO's unit for context is Creating a new task by default inherits the context from the current task. So if there's a feel that the whole thread is sharing a single connection, it's likely that there're some "dirty" connections shared in a very root context - e.g. unclosed connection during server startup.
Unfortunately not. This traces all the way back to an early discussion #84 even before PEP-567. In short, a workaround is to reset the context for each request, using
This is by design this way - if let's say you want to achieve async with engine.acquire():
await engine.all(...) Note the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Context:
I'm building a GraphQL service using:
Ariadne
FastAPI(Starlette)
Gino
aiodataloader
Gino serves most of my async requirements when it comes to calling the backend for data from an incoming request. However, I'm running into an interesting problem. When the incoming query has nested objects (or would result in multiple DB calls), e.g.
(in this case outlets, terminals, and pos providers are all separate DB calls), I end up getting an error from Asyncpg along the lines of
asyncpg.exceptions._base.InterfaceError: cannot perform operation: another operation is in progress
.As near I can tell from trawling through documentation and code, the combination of Gino with Dataloader results in a single connection being used for the same thread and all its related calls, at the same time. This is my current problem that I'd like help on.
What I've done:
After going through the docs for Gino and then reading through the source code, I found this in
engine.py
:At the moment this is the only method I'm using. But the crux for me was the
reuse
flag inself.acquire
. From my understanding of the code base and how this is used, I setreuse=False
and it solved my issue. Now, even in a same thread for Dataloader, Gino uses separate connections to make the required calls to the DB instead of firing all requests through the same connection at the same time. Plus the app remains performant. So from my understanding this is the solve for my particular case. But there might be something I'm missing.Question(s):
reuse=True
and there are multiple simultaneous calls to the DB in that same thread, the same connection will be used to satisfy the requests (all at once)?reuse
is by default False, but whenever we run those methods (e.g. snippet above) it's overwritten to True. Should this not be a parameter that can be passed on call? e.g.and the method could then be invoked as
obj = await query.gino.all(reuse=False)
This doesn't yet solve the issue of setting it at a global level, but it's a start I suppose.
Looking forward to hearing the community's thoughts.
Beta Was this translation helpful? Give feedback.
All reactions