Skip to content

Commit c727cea

Browse files
committed
Fix mypy type errors in update_incoming_fks implementation
- Add type annotation for incoming_fk_sqls: List[str] - Use self.db.table() instead of self.db[] to get Table type - Use setattr/getattr for _skip_fk_validation to avoid attr-defined error
1 parent 5ce545b commit c727cea

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

sqlite_utils/db.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,7 @@ def _get_incoming_fks_needing_update(self, rename: dict) -> list:
18671867
if other_table_name == self.name:
18681868
continue
18691869

1870-
other_table = self.db[other_table_name]
1870+
other_table = self.db.table(other_table_name)
18711871
other_fks = other_table.foreign_keys
18721872

18731873
# Check if any FK references a column being renamed
@@ -1927,26 +1927,26 @@ def transform(
19271927
assert self.exists(), "Cannot transform a table that doesn't exist yet"
19281928

19291929
# Collect SQL for updating incoming FKs if needed
1930-
incoming_fk_sqls = []
1930+
incoming_fk_sqls: List[str] = []
19311931
if update_incoming_fks and rename:
19321932
tables_needing_update = self._get_incoming_fks_needing_update(rename)
19331933
for other_table_name, new_fks in tables_needing_update:
1934-
other_table = self.db[other_table_name]
1934+
other_table = self.db.table(other_table_name)
19351935
# Generate transform SQL for the other table with updated FKs
19361936
# Skip FK validation since the new column doesn't exist yet
19371937
try:
1938-
self.db._skip_fk_validation = True
1938+
setattr(self.db, "_skip_fk_validation", True)
19391939
incoming_fk_sqls.extend(
19401940
other_table.transform_sql(foreign_keys=new_fks)
19411941
)
19421942
finally:
1943-
self.db._skip_fk_validation = False
1943+
setattr(self.db, "_skip_fk_validation", False)
19441944

19451945
# Skip FK validation for main transform if update_incoming_fks is True
19461946
# because self-referential FKs will reference the new column name
19471947
# that only exists after the transform completes
19481948
if update_incoming_fks and rename:
1949-
self.db._skip_fk_validation = True
1949+
setattr(self.db, "_skip_fk_validation", True)
19501950
try:
19511951
sqls = self.transform_sql(
19521952
types=types,
@@ -1963,7 +1963,7 @@ def transform(
19631963
)
19641964
finally:
19651965
if update_incoming_fks and rename:
1966-
self.db._skip_fk_validation = False
1966+
setattr(self.db, "_skip_fk_validation", False)
19671967

19681968
pragma_foreign_keys_was_on = self.db.execute("PRAGMA foreign_keys").fetchone()[
19691969
0

0 commit comments

Comments
 (0)