aerich icon indicating copy to clipboard operation
aerich copied to clipboard

AttributeError: 'NoneType' object has no attribute 'acquire'

Open solomn1991 opened this issue 4 years ago • 10 comments

I set my tortoise ORM like this `TORTOISE_ORM_CONFIG =
{ 'connections': {

        # Using a DB_URL string
        'default': 'mysql://root:123456@localhost:3306/SchoolManage'
    },
    'apps': {
        'models': {
            'models': ['database.models', "aerich.models"],
            # # If no default_connection specified, defaults to 'default'
            'default_connection': 'default',
        }
    }
}`

and I set the orm config in "database.py" module of a package like this ├── config │   ├── init.py │   └── database.py

then I input command aerich init -t config.database.TORTOISE_ORM_CONFIG it works,the 'pyproject.toml' appears

then I input 'aerich init-db'; it works,the tables appears in db;

then I change the model and execute 'aerich migrate' the error appears; here is the traceback infomations; 'Traceback (most recent call last): % aerich migrate File "/usr/local/bin/aerich", line 11, in sys.exit(main()) File "/usr/local/lib/python3.7/site-packages/aerich/cli.py", line 257, in main cli() File "/usr/local/lib/python3.7/site-packages/click/core.py", line 829, in call return self.main(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File "/usr/local/lib/python3.7/site-packages/click/core.py", line 610, in invoke return callback(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/click/decorators.py", line 21, in new_func return f(get_current_context(), *args, **kwargs) File "/usr/local/lib/python3.7/site-packages/aerich/cli.py", line 31, in wrapper loop.run_until_complete(f(*args, **kwargs)) File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete return future.result() File "/usr/local/lib/python3.7/site-packages/aerich/cli.py", line 86, in migrate ret = await command.migrate(name) File "/usr/local/lib/python3.7/site-packages/aerich/init.py", line 126, in migrate return await Migrate.migrate(name) File "/usr/local/lib/python3.7/site-packages/aerich/migrate.py", line 140, in migrate return await cls._generate_diff_sql(name) File "/usr/local/lib/python3.7/site-packages/aerich/migrate.py", line 112, in _generate_diff_sql version = await cls.generate_version(name) File "/usr/local/lib/python3.7/site-packages/aerich/migrate.py", line 102, in generate_version last_version_num = await cls._get_last_version_num() File "/usr/local/lib/python3.7/site-packages/aerich/migrate.py", line 93, in _get_last_version_num last_version = await cls.get_last_version() File "/usr/local/lib/python3.7/site-packages/aerich/migrate.py", line 55, in get_last_version return await Aerich.filter(app=cls.app).first() File "/usr/local/lib/python3.7/site-packages/tortoise/queryset.py", line 896, in _execute ).execute_select(self.query, custom_fields=list(self._annotations.keys())) File "/usr/local/lib/python3.7/site-packages/tortoise/backends/base/executor.py", line 124, in execute_select , raw_results = await self.db.execute_query(query.get_sql()) File "/usr/local/lib/python3.7/site-packages/tortoise/backends/mysql/client.py", line 44, in translate_exceptions return await func(self, *args) File "/usr/local/lib/python3.7/site-packages/tortoise/backends/mysql/client.py", line 196, in execute_query async with self.acquire_connection() as connection: File "/usr/local/lib/python3.7/site-packages/tortoise/backends/base/client.py", line 303, in aenter self.connection = await self.pool.acquire() AttributeError: 'NoneType' object has no attribute 'acquire' '

solomn1991 avatar Apr 22 '22 06:04 solomn1991

What's the models path?

long2ice avatar Apr 22 '22 08:04 long2ice

Hello, I'm getting this exact issue now as well, and I recall this working for me previously. I've just returned to my project after some time and have just returned and rebuilt my project virtualenv. Checking version, It appears Im on the latest (0.6.3). I've tried to set up a new db from scratch and can reproduce the issue. Ive downgraded my version to (0.5.8) and have recreated my database and aerich config from scratch - no issues. @solomn1991 if you can try to downgrade as well, might be worth a shot.

Posting my whole env below, just in case the versions help someone to debug:

aerich==0.5.8   # 0.6.3 was not working
aiodns==3.0.0
aiohttp==3.8.1
aiosignal==1.2.0
aiosqlite==0.17.0
anyio==3.5.0
asgiref==3.5.0
asttokens==2.0.5
async-timeout==4.0.2
asyncpg==0.25.0
attrs==21.4.0
backcall==0.2.0
bcrypt==3.2.0
cffi==1.15.0
charset-normalizer==2.0.12
click==8.1.2
cryptography==36.0.2
ddlparse==1.10.0
decorator==5.1.1
dictdiffer==0.9.0
dnspython==2.2.1
email-validator==1.1.3
executing==0.8.3
fastapi==0.75.2
fastapi-users==9.3.1
fastapi-users-db-tortoise==2.0.0
flake8==4.0.1
frozenlist==1.3.0
h11==0.13.0
httptools==0.4.0
idna==3.3
ipdb==0.13.9
ipython==8.2.0
iso8601==0.1.16
jedi==0.18.1
makefun==1.13.1
matplotlib-inline==0.1.3
mccabe==0.6.1
msgpack==1.0.3
multidict==6.0.2
parso==0.8.3
passlib==1.7.4
pexpect==4.8.0
pickleshare==0.7.5
prompt-toolkit==3.0.29
ptyprocess==0.7.0
pure-eval==0.2.2
py-algorand-sdk==1.12.0
pycares==4.1.2
pycodestyle==2.8.0
pycparser==2.21
pycryptodomex==3.14.1
pydantic==1.9.0
pyflakes==2.4.0
Pygments==2.11.2
PyJWT==2.3.0
PyNaCl==1.5.0
pyparsing==3.0.8
pypika-tortoise==0.1.4
python-dotenv==0.20.0
python-multipart==0.0.5
pytz==2022.1
PyYAML==6.0
six==1.16.0
sniffio==1.2.0
stack-data==0.2.0
starlette==0.17.1
toml==0.10.2
tomlkit==0.10.1
tortoise-orm==0.17.8
traitlets==5.1.1
typing_extensions==4.2.0
uvicorn==0.17.6
uvloop==0.16.0
watchgod==0.8.2
wcwidth==0.2.5
websockets==10.3
yarl==1.7.2

whereisrysmind avatar Apr 23 '22 03:04 whereisrysmind

backend ├── database │   ├── init.py │   └── models │   ├── Role.py │   ├── User.py │   ├── init.py

this is the structure of model path,R U Chinese?I’m Chinese.

solomn1991 avatar Apr 23 '22 03:04 solomn1991

What's the models path?

sorry, I,m not familiar with the page of github.the path is on upstairs

solomn1991 avatar Apr 23 '22 03:04 solomn1991

Hello, I'm getting this exact issue now as well, and I recall this working for me previously. I've just returned to my project after some time and have just returned and rebuilt my project virtualenv. Checking version, It appears Im on the latest (0.6.3). I've tried to set up a new db from scratch and can reproduce the issue. Ive downgraded my version to (0.5.8) and have recreated my database and aerich config from scratch - no issues. @solomn1991 if you can try to downgrade as well, might be worth a shot.

Posting my whole env below, just in case the versions help someone to debug:

aerich==0.5.8   # 0.6.3 was not working
aiodns==3.0.0
aiohttp==3.8.1
aiosignal==1.2.0
aiosqlite==0.17.0
anyio==3.5.0
asgiref==3.5.0
asttokens==2.0.5
async-timeout==4.0.2
asyncpg==0.25.0
attrs==21.4.0
backcall==0.2.0
bcrypt==3.2.0
cffi==1.15.0
charset-normalizer==2.0.12
click==8.1.2
cryptography==36.0.2
ddlparse==1.10.0
decorator==5.1.1
dictdiffer==0.9.0
dnspython==2.2.1
email-validator==1.1.3
executing==0.8.3
fastapi==0.75.2
fastapi-users==9.3.1
fastapi-users-db-tortoise==2.0.0
flake8==4.0.1
frozenlist==1.3.0
h11==0.13.0
httptools==0.4.0
idna==3.3
ipdb==0.13.9
ipython==8.2.0
iso8601==0.1.16
jedi==0.18.1
makefun==1.13.1
matplotlib-inline==0.1.3
mccabe==0.6.1
msgpack==1.0.3
multidict==6.0.2
parso==0.8.3
passlib==1.7.4
pexpect==4.8.0
pickleshare==0.7.5
prompt-toolkit==3.0.29
ptyprocess==0.7.0
pure-eval==0.2.2
py-algorand-sdk==1.12.0
pycares==4.1.2
pycodestyle==2.8.0
pycparser==2.21
pycryptodomex==3.14.1
pydantic==1.9.0
pyflakes==2.4.0
Pygments==2.11.2
PyJWT==2.3.0
PyNaCl==1.5.0
pyparsing==3.0.8
pypika-tortoise==0.1.4
python-dotenv==0.20.0
python-multipart==0.0.5
pytz==2022.1
PyYAML==6.0
six==1.16.0
sniffio==1.2.0
stack-data==0.2.0
starlette==0.17.1
toml==0.10.2
tomlkit==0.10.1
tortoise-orm==0.17.8
traitlets==5.1.1
typing_extensions==4.2.0
uvicorn==0.17.6
uvloop==0.16.0
watchgod==0.8.2
wcwidth==0.2.5
websockets==10.3
yarl==1.7.2

Thanks a lot ,the problem solved as I follow your hints

solomn1991 avatar Apr 23 '22 03:04 solomn1991

I had the same problem. It worked fine after rolled back the version to 0.6.2 and reinitializing the database. tortoise-orm: 0.18.1

jonarsli avatar Apr 24 '22 17:04 jonarsli

The same issue 🤔

coffeewasmyidea avatar May 09 '22 21:05 coffeewasmyidea

https://github.com/tortoise/aerich/pull/242 fix it?

long2ice avatar May 10 '22 00:05 long2ice

#242 fix it?

Yep, I tested it in many ways 👌

coffeewasmyidea avatar May 10 '22 07:05 coffeewasmyidea

Same issue.

TheBubblePopped avatar Jul 22 '22 00:07 TheBubblePopped