Trying to run tortoise with quart async rest api
See original GitHub issueDescribe the bug Hi,
I have simple tortoise example that work fine when i create the python event loop and run it. but when i run Quart API server I get strange error, I braked my head trying to figure out what is the issue (I’m running python3.7) The script I ran is below:
import asyncio
from tortoise import Tortoise, fields
from tortoise.models import Model
from quart import Quart, request, abort
app = Quart(__name__)
app.config.from_object(config)
class Users(Model):
id = fields.IntField(pk=True)
status = fields.CharField(20)
def __repr__(self):
return str(self.id)
class Workers(Model):
id = fields.IntField(pk=True)
status = fields.CharField(20)
def __repr__(self):
return str(self.id)
@app.before_first_request
async def initial_db():
await Tortoise.init({
'connections': {
'default': "postgres://localhost:5432/db",
'second': "postgres://localhost:5432/db",
},
'apps': {
'users': {
'models': ['__main__'],
'default_connection': 'default',
},
'workers': {
'models': ['__main__'],
'default_connection': 'second',
}
}
})
def run_quart():
app.run(port=5002)
def run_tortoise():
loop = asyncio.get_event_loop()
loop.run_until_complete(initial_db())
if __name__ == '__main__':
# run_quart() # not working
run_tortoise() # working
To Reproduce run one time the “run_quart” see the error then run “run_tortoise” see the run succeed
Expected behavior tortoise ORM will use the Quart event loop
Actual behavior Tortoise raise “NotADirectoryError” error
Additional context This is my first time using Tortoise ORM and its looking very cool, I will appreciate any help with this issue
Thanks in advanced!
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Quart Example — Tortoise ORM v0.17.3 Documentation
This is an example of the Tortoise-ORM Quart integration ... To generate schemas QUART_APP=main quart generate-schemas # To run QUART_APP=main quart run ......
Read more >python-quart/lobby - Gitter
CAVEAT: Using this solution provides a single database session per request. So the session is used for all synchronous and asynchronous code within...
Read more >Tutorial: Building a RESTful API — Quart 0.17.0 documentation
In this tutorial we will build a RESTful JSON API. It will automatically generate OpenAPI documentation and validate request and response data. This...
Read more >What is the right way to initialize database using tortoise orm ...
Consider using an asyncio-based framework, such as Quart/aiohttp/starlette, both that and Tortoise-ORM the uses the same concurrency method and ...
Read more >Quart; an ASGI alternative to Flask - TIB AV-Portal
Quart is the solution as it shares the Flask API and is based on asyncio. ... although some extensions (Flask-Aiohttp) have tried. Quart...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
very strange … cause i just run it using python3.6 and the integration worked! but when comeback to python3.7 the error raised aggain … maybe my virtual env is massed up or something I will create new one and check it again
Thakns @grigi 😃
It ran for me. I used py3.6.6 and Quart==0.6.12 tortoise-orm==0.11.8 asyncpg==0.18.3
So I should try this on Py3.7 I suppose they changed their api. And I see py3.6 is limited to the older version.