MissingGreenlet exception while creating both parent and child instances and returning parent #1323
Unanswered
ArazHeydarov
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
Receiving
sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an unexpected place? (Background on this error at: https://sqlalche.me/e/20/xd2s)
Disclaimer: It's possible that the problem is related to
SQLAlchemy
greenlet contexts; however, since the error happens when I try to return the Parent asresponse model
, I thought this place is more suitable for opening this discussion.The most important note here is that the problem only happens when the instances are not in DB and they are created. If you make a
POST
request 3 times, where all Parent and Instances are created, you don't receive any exceptions afterwards.To reproduce the issue, send a
POST
request tolocalhost:8000/parent
with body:The problem is not related to
async lazy loading
; for this purpose, I also added aget
endpoint to show that it works without any issues.Operating System
macOS
Operating System Details
No response
SQLModel Version
sqlmodel==0.0.24
Python Version
Python 3.13.2
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions