AttributeError: 'NoneType' object has no attribute 'decode' with asyncpg
See original GitHub issueDescribe the bug
Application doesn’t start with asyncpg and generate_schemas
param.
ERROR:uvicorn.error:Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/starlette/routing.py", line 473, in __call__
await self.startup()
File "/usr/local/lib/python3.7/site-packages/starlette/routing.py", line 457, in startup
await handler()
File "/usr/local/lib/python3.7/site-packages/tortoise/contrib/starlette/__init__.py", line 80, in init_orm
await Tortoise.generate_schemas()
File "/usr/local/lib/python3.7/site-packages/tortoise/__init__.py", line 682, in generate_schemas
await generate_schema_for_client(connection, safe)
File "/usr/local/lib/python3.7/site-packages/tortoise/utils.py", line 16, in generate_schema_for_client
await generator.generate_from_string(schema)
File "/usr/local/lib/python3.7/site-packages/tortoise/backends/base/schema_generator.py", line 374, in generate_from_string
await self.client.execute_script(creation_string)
File "/usr/local/lib/python3.7/site-packages/tortoise/backends/asyncpg/client.py", line 33, in translate_exceptions_
return await func(self, *args)
File "/usr/local/lib/python3.7/site-packages/tortoise/backends/asyncpg/client.py", line 173, in execute_script
await connection.execute(query)
File "/usr/local/lib/python3.7/site-packages/asyncpg/connection.py", line 272, in execute
return await self._protocol.query(query, timeout)
File "asyncpg/protocol/protocol.pyx", line 316, in query
File "asyncpg/protocol/protocol.pyx", line 807, in asyncpg.protocol.protocol.BaseProtocol._dispatch_result
File "asyncpg/protocol/protocol.pyx", line 734, in asyncpg.protocol.protocol.BaseProtocol._on_result__simple_query
AttributeError: 'NoneType' object has no attribute 'decode'
[2019-11-29 12:02:31 +0000] [37] [ERROR] Application startup failed. Exiting.
{"loglevel": "info", "workers": 1, "bind": "0.0.0.0:8080", "workers_per_core": 1.0, "host": "0.0.0.0", "port": "8080"}
ERROR:uvicorn.error:Application startup failed. Exiting.
[2019-11-29 12:02:31 +0000] [37] [INFO] Worker exiting (pid: 37)
To Reproduce
DB_MODELS = ["app.models.db.tortoise"]
DB_CONFIG = {
'connections': {
'default': {
'engine': 'tortoise.backends.asyncpg',
'credentials': {
'host': 'postgres',
'port': '5432',
'user': 'postgres',
'password': 'postgres',
'database': 'mydb',
}
},
},
'apps': {
'models': {
'models': DB_MODELS,
'default_connection': 'default',
}
}
}
def init_db(app: FastAPI):
register_tortoise(
app, generate_schemas=True, config=DB_CONFIG
)
NOTE: Folder that should contain the models app.models.db.tortoise
is empty (except __init__.py
file.)
Expected behavior I think application should start 😄
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
AttributeError: "NoneType" object has no attribute 'decode'
Optional decode is a flag indicating whether the payload should be decoded or not, according to the Content-Transfer-Encoding header.
Read more >Attributeerror: 'Nonetype' Object Has No Attribute 'Decode ...
Python returns an error stating AttributeError: 'str' object has no attribute 'append' if We walk through an example of this error in action...
Read more >AttributeError: 'NoneType' object has no attribute 'decode'
Coding example for the question AttributeError: 'NoneType' object has no attribute 'decode'
Read more >asyncpg Usage
import asyncio import asyncpg import datetime async def main(): ... The table below shows the correspondence between PostgreSQL and Python types.
Read more >'str' object has no attribute 'decode'. Python 3 error? - YouTube
PYTHON : 'str' object has no attribute ' decode '. Python 3 error? [ Gift : Animated Search Engine : https://www.hows.tech/p/recommended.html ] ...
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
Please test v0.15.4
It now emits a
RuntimeWarning
when a module has no models to import, and should not crash like OP, please test 😄Thanks so much! I have tested it and it works awesome!