Skip to content

Doesn't work in a uvicorn web worker #2

Description

@owais

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))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions