Skip to content

Commit

Permalink
Fix logging issue where "Before fixing" modified time is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
barrywhart committed Jan 23, 2024
1 parent 29db4f4 commit 00deda2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/dbt_core_interface/sqlfluff_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def format_command(
else:
# Format a SQL file
LOGGER.info(f"Formatting SQL file: {sql}")
before_modified = datetime.fromtimestamp(sql.stat().st_mtime).strftime('%Y-%m-%d %H:%M:%S')
LOGGER.info(f"Before fixing, modified: {before_modified}")
result_sql = None
lint_result = lnt.lint_paths(
paths=[str(sql)],
Expand All @@ -197,15 +199,15 @@ def format_command(
num_fixable = lint_result.num_violations(types=SQLLintError, fixable=True)
if num_fixable > 0:
LOGGER.info(f"Fixing {num_fixable} errors in SQL file")
before_modified = datetime.fromtimestamp(sql.stat().st_mtime).strftime('%Y-%m-%d %H:%M:%S')
LOGGER.info(f"Before fixing, modified: {before_modified}")
res = lint_result.persist_changes(
formatter=formatter, fixed_file_suffix=""
)
after_modified = datetime.fromtimestamp(sql.stat().st_mtime).strftime('%Y-%m-%d %H:%M:%S')
LOGGER.info(f"After fixing, modified: {after_modified}")
LOGGER.info(f"File modification time has changes? {before_modified != after_modified}")
success = all(res.values())
else:
LOGGER.info("No fixable errors in SQL file")
LOGGER.info(f"format_command returning success={success}, result_sql={result_sql[:100] if result_sql is not None else 'n/a'}")
return success, result_sql

Expand Down

0 comments on commit 00deda2

Please sign in to comment.