Skip to content

Error while running django async #199

@niranjrajasekaran

Description

@niranjrajasekaran

Environment

Django 3.2
Python 3.9
DB Sqlite3

I am running django using asgi. I have installed river and have done DB migrations, Here is my models.py

from river.models.fields.state import StateField

class Project(models.Model):
    ...
    status = StateField()
    ...

I am able to run my application only if the status is commented out or else I am getting this error

 File "/Users/mac/Library/Caches/pypoetry/virtualenvs/gozeal-Lr0Dg4MF-py3.9/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/Users/mac/Library/Caches/pypoetry/virtualenvs/gozeal-Lr0Dg4MF-py3.9/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/mac/Library/Caches/pypoetry/virtualenvs/gozeal-Lr0Dg4MF-py3.9/lib/python3.9/site-packages/django/apps/registry.py", line 122, in populate
    app_config.ready()
  File "/Users/mac/Library/Caches/pypoetry/virtualenvs/gozeal-Lr0Dg4MF-py3.9/lib/python3.9/site-packages/river/apps.py", line 20, in ready
    if workflows.count() == 0:
  File "/Users/mac/Library/Caches/pypoetry/virtualenvs/gozeal-Lr0Dg4MF-py3.9/lib/python3.9/site-packages/django/db/models/query.py", line 412, in count
    return self.query.get_count(using=self.db)
  File "/Users/mac/Library/Caches/pypoetry/virtualenvs/gozeal-Lr0Dg4MF-py3.9/lib/python3.9/site-packages/django/db/models/sql/query.py", line 519, in get_count
    number = obj.get_aggregation(using, ['__count'])['__count']
  File "/Users/mac/Library/Caches/pypoetry/virtualenvs/gozeal-Lr0Dg4MF-py3.9/lib/python3.9/site-packages/django/db/models/sql/query.py", line 504, in get_aggregation
    result = compiler.execute_sql(SINGLE)
  File "/Users/mac/Library/Caches/pypoetry/virtualenvs/gozeal-Lr0Dg4MF-py3.9/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1173, in execute_sql
    cursor = self.connection.cursor()
  File "/Users/mac/Library/Caches/pypoetry/virtualenvs/gozeal-Lr0Dg4MF-py3.9/lib/python3.9/site-packages/django/utils/asyncio.py", line 24, in inner
    raise SynchronousOnlyOperation(message)
django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.

It could be great if someone can give pointers to solve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions