diff --git a/Makefile b/Makefile index e9b807c..9e97a17 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,8 @@ style: deps _style _check: @black --check $(black_opts) $(checkfiles) || (echo "Please run 'make style' to auto-fix style issues" && false) @ruff check $(checkfiles) + @mypy $(checkfiles) + @bandit -r aerich check: deps _check test: deps diff --git a/aerich/ddl/__init__.py b/aerich/ddl/__init__.py index 4e062c7..cb57274 100644 --- a/aerich/ddl/__init__.py +++ b/aerich/ddl/__init__.py @@ -135,7 +135,7 @@ class BaseDDL: self.schema_generator._column_comment_generator( table=db_table, column=db_column, - comment=field_describe.get("description"), + comment=description, ) if description else "" diff --git a/aerich/inspectdb/postgres.py b/aerich/inspectdb/postgres.py index d4a7761..f77bc29 100644 --- a/aerich/inspectdb/postgres.py +++ b/aerich/inspectdb/postgres.py @@ -56,7 +56,7 @@ from information_schema.constraint_column_usage const right join information_schema.columns c using (column_name, table_catalog, table_schema, table_name) where c.table_catalog = $1 and c.table_name = $2 - and c.table_schema = $3""" + and c.table_schema = $3""" # nosec:B608 ret = await self.conn.execute_query_dict(sql, [self.database, table, self.schema]) for row in ret: columns.append( diff --git a/tests/test_migrate.py b/tests/test_migrate.py index 4614606..e7115d9 100644 --- a/tests/test_migrate.py +++ b/tests/test_migrate.py @@ -1,4 +1,5 @@ from pathlib import Path +from typing import List, cast import pytest import tortoise @@ -792,13 +793,13 @@ old_models_describe = { def should_add_user_id_column_type_alter_sql() -> bool: + if tortoise.__version__ < "0.21": + return False # tortoise-orm>=0.21 changes IntField constraints # from {"ge": 1, "le": 2147483647} to {"ge": -2147483648,"le": 2147483647} - user_id_constraints = old_models_describe["models.Category"]["data_fields"][-1]["constraints"] - return ( - tortoise.__version__ >= "0.21" - and tortoise.fields.data.IntField.constraints != user_id_constraints - ) + data_fields = cast(List[dict], old_models_describe["models.Category"]["data_fields"]) + user_id_constraints = data_fields[-1]["constraints"] + return tortoise.fields.data.IntField.constraints != user_id_constraints def test_migrate(mocker: MockerFixture): @@ -825,6 +826,7 @@ def test_migrate(mocker: MockerFixture): if isinstance(Migrate.ddl, SqliteDDL): with pytest.raises(NotSupportError): Migrate.diff_models(old_models_describe, models_describe) + with pytest.raises(NotSupportError): Migrate.diff_models(models_describe, old_models_describe, False) else: Migrate.diff_models(old_models_describe, models_describe)