mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
refactor: Enable G logging rules and comprehensive ruff improvements (#35081)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
e1a2e4843a
commit
088ecdd0bf
@@ -227,7 +227,13 @@ def drop_fks_for_table(
|
||||
|
||||
for fk_name in foreign_key_names:
|
||||
logger.info(
|
||||
f"Dropping foreign key {GREEN}{fk_name}{RESET} from table {GREEN}{table_name}{RESET}..." # noqa: E501
|
||||
"Dropping foreign key %s%s%s from table %s%s%s...", # noqa: E501
|
||||
GREEN,
|
||||
fk_name,
|
||||
RESET,
|
||||
GREEN,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
op.drop_constraint(fk_name, table_name, type_="foreignkey")
|
||||
|
||||
@@ -246,12 +252,12 @@ def create_table(table_name: str, *columns: SchemaItem, **kwargs: Any) -> None:
|
||||
just like when calling alembic's method create_table()
|
||||
"""
|
||||
if has_table(table_name=table_name):
|
||||
logger.info(f"Table {LRED}{table_name}{RESET} already exists. Skipping...")
|
||||
logger.info("Table %s%s%s already exists. Skipping...", LRED, table_name, RESET)
|
||||
return
|
||||
|
||||
logger.info(f"Creating table {GREEN}{table_name}{RESET}...")
|
||||
logger.info("Creating table %s%s%s...", GREEN, table_name, RESET)
|
||||
op.create_table(table_name, *columns, **kwargs)
|
||||
logger.info(f"Table {GREEN}{table_name}{RESET} created.")
|
||||
logger.info("Table %s%s%s created.", GREEN, table_name, RESET)
|
||||
|
||||
|
||||
def drop_table(table_name: str) -> None:
|
||||
@@ -267,13 +273,13 @@ def drop_table(table_name: str) -> None:
|
||||
""" # noqa: E501
|
||||
|
||||
if not has_table(table_name=table_name):
|
||||
logger.info(f"Table {GREEN}{table_name}{RESET} doesn't exist. Skipping...")
|
||||
logger.info("Table %s%s%s doesn't exist. Skipping...", GREEN, table_name, RESET)
|
||||
return
|
||||
|
||||
logger.info(f"Dropping table {GREEN}{table_name}{RESET}...")
|
||||
logger.info("Dropping table %s%s%s...", GREEN, table_name, RESET)
|
||||
drop_fks_for_table(table_name)
|
||||
op.drop_table(table_name=table_name)
|
||||
logger.info(f"Table {GREEN}{table_name}{RESET} dropped.")
|
||||
logger.info("Table %s%s%s dropped.", GREEN, table_name, RESET)
|
||||
|
||||
|
||||
def batch_operation(
|
||||
@@ -295,17 +301,31 @@ def batch_operation(
|
||||
""" # noqa: E501
|
||||
if count <= 0:
|
||||
logger.info(
|
||||
f"No records to process in batch {LRED}(count <= 0){RESET} for callable {LRED}other_callable_example{RESET}. Skipping..." # noqa: E501
|
||||
"No records to process in batch %s(count <= 0)%s for callable %sother_callable_example%s. Skipping...", # noqa: E501
|
||||
LRED,
|
||||
RESET,
|
||||
LRED,
|
||||
RESET,
|
||||
)
|
||||
return
|
||||
for offset in range(0, count, batch_size):
|
||||
percentage = (offset / count) * 100 if count else 0
|
||||
logger.info(f"Progress: {offset:,}/{count:,} ({percentage:.2f}%)")
|
||||
logger.info(
|
||||
"Progress: %s/%s (%.2f%%)",
|
||||
"{:,}".format(offset),
|
||||
"{:,}".format(count),
|
||||
percentage,
|
||||
)
|
||||
callable(offset, min(offset + batch_size, count))
|
||||
|
||||
logger.info(f"Progress: {count:,}/{count:,} (100%)")
|
||||
logger.info("Progress: %s/%s (100%%)", "{:,}".format(count), "{:,}".format(count))
|
||||
logger.info(
|
||||
f"End: {GREEN}{callable.__name__}{RESET} batch operation {GREEN}successfully{RESET} executed." # noqa: E501
|
||||
"End: %s%s%s batch operation %ssuccessfully%s executed.", # noqa: E501
|
||||
GREEN,
|
||||
callable.__name__,
|
||||
RESET,
|
||||
GREEN,
|
||||
RESET,
|
||||
)
|
||||
|
||||
|
||||
@@ -326,7 +346,13 @@ def add_columns(table_name: str, *columns: Column) -> None:
|
||||
for col in columns:
|
||||
if table_has_column(table_name=table_name, column_name=col.name):
|
||||
logger.info(
|
||||
f"Column {LRED}{col.name}{RESET} already present on table {LRED}{table_name}{RESET}. Skipping..." # noqa: E501
|
||||
"Column %s%s%s already present on table %s%s%s. Skipping...", # noqa: E501
|
||||
LRED,
|
||||
col.name,
|
||||
RESET,
|
||||
LRED,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
else:
|
||||
cols_to_add.append(col)
|
||||
@@ -334,7 +360,13 @@ def add_columns(table_name: str, *columns: Column) -> None:
|
||||
with op.batch_alter_table(table_name) as batch_op:
|
||||
for col in cols_to_add:
|
||||
logger.info(
|
||||
f"Adding column {GREEN}{col.name}{RESET} to table {GREEN}{table_name}{RESET}..." # noqa: E501
|
||||
"Adding column %s%s%s to table %s%s%s...", # noqa: E501
|
||||
GREEN,
|
||||
col.name,
|
||||
RESET,
|
||||
GREEN,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
batch_op.add_column(col)
|
||||
|
||||
@@ -356,7 +388,13 @@ def drop_columns(table_name: str, *columns: str) -> None:
|
||||
for col in columns:
|
||||
if not table_has_column(table_name=table_name, column_name=col):
|
||||
logger.info(
|
||||
f"Column {LRED}{col}{RESET} is not present on table {LRED}{table_name}{RESET}. Skipping..." # noqa: E501
|
||||
"Column %s%s%s is not present on table %s%s%s. Skipping...", # noqa: E501
|
||||
LRED,
|
||||
col,
|
||||
RESET,
|
||||
LRED,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
else:
|
||||
cols_to_drop.append(col)
|
||||
@@ -364,7 +402,13 @@ def drop_columns(table_name: str, *columns: str) -> None:
|
||||
with op.batch_alter_table(table_name) as batch_op:
|
||||
for col in cols_to_drop:
|
||||
logger.info(
|
||||
f"Dropping column {GREEN}{col}{RESET} from table {GREEN}{table_name}{RESET}..." # noqa: E501
|
||||
"Dropping column %s%s%s from table %s%s%s...", # noqa: E501
|
||||
GREEN,
|
||||
col,
|
||||
RESET,
|
||||
GREEN,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
batch_op.drop_column(col)
|
||||
|
||||
@@ -386,12 +430,24 @@ def create_index(
|
||||
|
||||
if table_has_index(table=table_name, index=index_name):
|
||||
logger.info(
|
||||
f"Table {LRED}{table_name}{RESET} already has index {LRED}{index_name}{RESET}. Skipping..." # noqa: E501
|
||||
"Table %s%s%s already has index %s%s%s. Skipping...", # noqa: E501
|
||||
LRED,
|
||||
table_name,
|
||||
RESET,
|
||||
LRED,
|
||||
index_name,
|
||||
RESET,
|
||||
)
|
||||
return
|
||||
|
||||
logger.info(
|
||||
f"Creating index {GREEN}{index_name}{RESET} on table {GREEN}{table_name}{RESET}"
|
||||
"Creating index %s%s%s on table %s%s%s",
|
||||
GREEN,
|
||||
index_name,
|
||||
RESET,
|
||||
GREEN,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
@@ -415,12 +471,24 @@ def drop_index(table_name: str, index_name: str) -> None:
|
||||
|
||||
if not table_has_index(table=table_name, index=index_name):
|
||||
logger.info(
|
||||
f"Table {LRED}{table_name}{RESET} doesn't have index {LRED}{index_name}{RESET}. Skipping..." # noqa: E501
|
||||
"Table %s%s%s doesn't have index %s%s%s. Skipping...", # noqa: E501
|
||||
LRED,
|
||||
table_name,
|
||||
RESET,
|
||||
LRED,
|
||||
index_name,
|
||||
RESET,
|
||||
)
|
||||
return
|
||||
|
||||
logger.info(
|
||||
f"Dropping index {GREEN}{index_name}{RESET} from table {GREEN}{table_name}{RESET}..." # noqa: E501
|
||||
"Dropping index %s%s%s from table %s%s%s...", # noqa: E501
|
||||
GREEN,
|
||||
index_name,
|
||||
RESET,
|
||||
GREEN,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
|
||||
op.drop_index(table_name=table_name, index_name=index_name)
|
||||
@@ -448,7 +516,10 @@ def create_fks_for_table(
|
||||
|
||||
if not has_table(table_name):
|
||||
logger.warning(
|
||||
f"Table {LRED}{table_name}{RESET} does not exist. Skipping foreign key creation." # noqa: E501
|
||||
"Table %s%s%s does not exist. Skipping foreign key creation.", # noqa: E501
|
||||
LRED,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -456,7 +527,13 @@ def create_fks_for_table(
|
||||
# SQLite requires batch mode since ALTER TABLE is limited
|
||||
with op.batch_alter_table(table_name) as batch_op:
|
||||
logger.info(
|
||||
f"Creating foreign key {GREEN}{foreign_key_name}{RESET} on table {GREEN}{table_name}{RESET} (SQLite mode)..." # noqa: E501
|
||||
"Creating foreign key %s%s%s on table %s%s%s (SQLite mode)...", # noqa: E501
|
||||
GREEN,
|
||||
foreign_key_name,
|
||||
RESET,
|
||||
GREEN,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
batch_op.create_foreign_key(
|
||||
foreign_key_name,
|
||||
@@ -468,7 +545,13 @@ def create_fks_for_table(
|
||||
else:
|
||||
# Standard FK creation for other databases
|
||||
logger.info(
|
||||
f"Creating foreign key {GREEN}{foreign_key_name}{RESET} on table {GREEN}{table_name}{RESET}..." # noqa: E501
|
||||
"Creating foreign key %s%s%s on table %s%s%s...", # noqa: E501
|
||||
GREEN,
|
||||
foreign_key_name,
|
||||
RESET,
|
||||
GREEN,
|
||||
table_name,
|
||||
RESET,
|
||||
)
|
||||
op.create_foreign_key(
|
||||
foreign_key_name,
|
||||
@@ -541,7 +624,11 @@ USING safe_to_jsonb({column});
|
||||
json.loads(value)
|
||||
except json.JSONDecodeError:
|
||||
logger.warning(
|
||||
f"Invalid JSON value in column {column} for {pk}={row_pk}: {value}"
|
||||
"Invalid JSON value in column %s for %s=%s: %s",
|
||||
column,
|
||||
pk,
|
||||
row_pk,
|
||||
value,
|
||||
)
|
||||
continue
|
||||
stmt_update = update(t).where(t.c[pk] == row_pk).values({tmp_column: value})
|
||||
|
||||
Reference in New Issue
Block a user