-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
I tried running some queries inside a django channels consumer and it threw this error:
RuntimeError: No TortoiseContext is currently active. Use 'async with TortoiseContext() as ctx:' to create one, or call Tortoise.init() for global state.
The following management command works though manage.py run test_tortoise_orm
async def _run_tortoise_test() -> str:
count = await MyModel.tortoise_objects.all().count()
return f"count() = {count}"
class Command(BaseCommand):
def handle(self, *args, **options):
result = asyncio.run(_run_tortoise_test())
self.stdout.write(self.style.SUCCESS(result))
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels