Unable to create models
See original GitHub issueChecklist
- The bug is reproducible against the latest release and/or
master
. - There are no similar issues or pull requests to fix it yet.
Describe the bug
Unable to create models due to a RuntimeError caused by anyio.
To reproduce
database = databases.Database("url")
models = orm.ModelRegistry(database = database)
models.create_all()
Expected behavior
Models getting created. Successfully connecting to the database.
Actual behavior
The models don’t get created due to the RuntimeError being raised by anyio and it fails to connect to the database.
Debugging material
Traceback from ipython
RuntimeError Traceback (most recent call last)
<ipython-input-1-3765cc235a53> in <module>
16
17 # Create the tables
---> 18 models.create_all()
19
20 await Note.objects.create(text="Buy the groceries.", completed=False)
/data/data/com.termux/files/usr/lib/python3.9/site-packages/orm/models.py in create_all(self)
31 def create_all(self):
32 url = self._get_database_url()
---> 33 anyio.run(self._create_all, url)
34
35 def drop_all(self):
/data/data/com.termux/files/usr/lib/python3.9/site-packages/anyio/_core/_eventloop.py in run(func, backend, backend_options, *args)
40 pass
41 else:
---> 42 raise RuntimeError(f'Already running {asynclib_name} in this thread')
43
44 try:
RuntimeError: Already running asyncio in this thread
Environment
- OS: Linux aarch64 Android
- Python version: 3.9.7
- ORM version: 0.2.0
Additional context
I fixed it by making create_all
an async function and using await self._create_all(url)
instead of anyio.run(self._create_all, url)
although I don’t think that’s the best way to fix this.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:38 (16 by maintainers)
Top Results From Across the Web
"We were unable to create your model due to technical issues ...
"We were unable to create your model due to technical issues" when creating a model using Model Builder in InfraWorks.
Read more >Unable to create a model with Eloquent create method. Error ...
I have created a model named, Author. I tried creating a model with the help of eloquent create method like this:
Read more >model.save() throwed out an OSError: Unable to create file ...
My workaround is to create a new callback which saves models/weights after each epoch with a new file name. Calling model.save() or model....
Read more >Unable To Create A Data Model - Oracle Support
Unable To Create A Data Model (Doc ID 2123460.1) ... The below error occurs when creating a BI Data model via the Weblogic...
Read more >Unable to create new Model entry - Odoo
I have tried to create a new model field with Odoo's UI. I Click on Settings->Developer Mode-> Technical-> Database Structure->Models and I try...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ill come back with a pytest reproducible example on this point.
I think that misses a few imports and stuff, I could reproduce it with this example:
app.py
and running
uvicorn app:app
causes: