DEV Community

Valentino Gagliardi
Valentino Gagliardi

Posted on • Originally published at

[Video] Asynchronous tasks in Django with Django Q (Part 3)

Django Q is a scheduler and a task queue for Django. In this series you'll learn how to use Django Q in your Django applications for queuing long-running tasks.

In this episode:

  • hands on Django Q
  • using async_task


Top comments (1)

jramiresbrito profile image
João Victor Ramires Guimarães Brito • Edited

Hey, first of all thanks for sharing!

I'm trying to populate my database using a Data Migration.

In my populate function I have 2 api calls, so the shape is something like this:

async def populate_table(apps, schema_editor):
    some stuff...
    an api call like: await get_info()...
    an api call inside a for loop (any problem with this?)
    for i in range():
       an api call like: await get_another_info()...
    more stuff...

And then, I have my migration class:

class Migration(migrations.Migration):

    dependencies = [
        ('app', 'the previous migration'),

    operations = [

Running the migration a Runtime Warning is raised:

RuntimeWarning: coroutine 'populate_table' was never awaited

So I try to decorate my Migration with Async Await without success.

How should I do that? And again, any problem to have async tasks inside a sync for loop?