# \[SOLVED\] OperationalError and SynchronousOnlyOperation with async

**URL:** <https://forum.djangoproject.com/t/solved-operationalerror-and-synchronousonlyoperation-with-async/5801>\
**Category:** Using Django\
**Created:** [December 22, 2020, 2:30pm UTC](https://forum.djangoproject.com/t/solved-operationalerror-and-synchronousonlyoperation-with-async/5801 "2020-12-22T14:30:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![valentinogagliardi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/valentinogagliardi/32/607_2.png) [@valentinogagliardi](https://forum.djangoproject.com/u/valentinogagliardi)\
**Post date:** [December 22, 2020, 2:30pm UTC](https://forum.djangoproject.com/t/solved-operationalerror-and-synchronousonlyoperation-with-async/5801/1 "2020-12-22T14:30:11Z")

</div>

Hi there!

I am experimenting with asynchronous Django, specifically I’m trying to make this test pass:

```python
class SomeAsyncTest(TestCase):
    def _make_user(self):
        return User.objects.create_user(
            username="John", email="Doe", password="not-secret"
        )

    def _force_login(self, user):
        return self.async_client.force_login(user)

    @override_settings(
        MIDDLEWARE=[
            "django.contrib.sessions.middleware.SessionMiddleware",
            "django.contrib.auth.middleware.AuthenticationMiddleware",
        ]
    )
    async def test_it_sends_email_to_admins(self):
        os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
        user = await sync_to_async(self._make_user)()
        await sync_to_async(self._force_login)(user)
        await self.async_client.get("/secret-area/")
        # and more

```

The database for this test is Sqlite3, and without `DJANGO_ALLOW_ASYNC_UNSAFE` I get `django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async`, which I understand where it comes from.

If I make it “true” instead, I get `django.db.utils.OperationalError: database table is locked: django_session`.

I understand the ORM is not async at this moment, but there is a way to make this test pass? Could depend from the Sqlite backend? What am I doing wrong?

**EDIT** : this should be Sqlite. It can’t handle concurrent connections, I forgot! It seems to work with Postgres, but I need to debug one last thing: `PytestWarning: Error when trying to teardown test databases: RuntimeError("generator didn't stop after throw()")`.

Thanks in advance!
