Skip to content

Commit c42bce4

Browse files
authored
Fix: make logger respect --ignore-warnings (#4354)
1 parent 5b2fa5b commit c42bce4

4 files changed

Lines changed: 68 additions & 3 deletions

File tree

sqlmesh/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def configure_logging(
172172
write_to_file: bool = True,
173173
log_limit: int = c.DEFAULT_LOG_LIMIT,
174174
log_file_dir: t.Optional[t.Union[str, Path]] = None,
175+
ignore_warnings: bool = False,
175176
) -> None:
176177
# Remove noisy grpc logs that are not useful for users
177178
os.environ["GRPC_VERBOSITY"] = os.environ.get("GRPC_VERBOSITY", "NONE")
@@ -186,7 +187,7 @@ def configure_logging(
186187
if write_to_stdout:
187188
stdout_handler = logging.StreamHandler(sys.stdout)
188189
stdout_handler.setFormatter(CustomFormatter())
189-
stdout_handler.setLevel(level)
190+
stdout_handler.setLevel(logging.ERROR if ignore_warnings else level)
190191
logger.addHandler(stdout_handler)
191192

192193
log_file_dir = log_file_dir or c.DEFAULT_LOG_FILE_DIR

sqlmesh/cli/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ def cli(
102102

103103
configs = load_configs(config, Context.CONFIG_TYPE, paths)
104104
log_limit = list(configs.values())[0].log_limit
105-
configure_logging(debug, log_to_stdout, log_limit=log_limit, log_file_dir=log_file_dir)
105+
configure_logging(
106+
debug,
107+
log_to_stdout,
108+
log_limit=log_limit,
109+
log_file_dir=log_file_dir,
110+
ignore_warnings=ignore_warnings,
111+
)
106112
configure_console(ignore_warnings=ignore_warnings)
107113

108114
try:

sqlmesh/magics.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@ def context(self, line: str) -> None:
134134
args = parse_argstring(self.context, line)
135135
configs = load_configs(args.config, Context.CONFIG_TYPE, args.paths)
136136
log_limit = list(configs.values())[0].log_limit
137-
configure_logging(args.debug, log_limit=log_limit, log_file_dir=args.log_file_dir)
137+
configure_logging(
138+
args.debug,
139+
log_limit=log_limit,
140+
log_file_dir=args.log_file_dir,
141+
ignore_warnings=args.ignore_warnings,
142+
)
138143
configure_console(ignore_warnings=args.ignore_warnings)
139144
try:
140145
context = Context(paths=args.paths, config=configs, gateway=args.gateway)

tests/cli/test_cli.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,3 +1706,56 @@ def test_dbt_init(tmp_path):
17061706
config = sqlmesh_config(Path(__file__).parent)
17071707
"""
17081708
)
1709+
1710+
1711+
def test_ignore_warnings(runner: CliRunner, tmp_path: Path) -> None:
1712+
create_example_project(tmp_path)
1713+
1714+
# Add non-blocking audit to generate WARNING
1715+
with open(tmp_path / "models" / "full_model.sql", "w", encoding="utf-8") as f:
1716+
f.write("""
1717+
MODEL (
1718+
name sqlmesh_example.full_model,
1719+
kind FULL,
1720+
cron '@daily',
1721+
grain item_id,
1722+
audits (full_nonblocking_audit),
1723+
);
1724+
1725+
SELECT
1726+
item_id,
1727+
COUNT(DISTINCT id) AS num_orders,
1728+
FROM
1729+
sqlmesh_example.incremental_model
1730+
GROUP BY item_id;
1731+
1732+
AUDIT (
1733+
name full_nonblocking_audit,
1734+
blocking false,
1735+
);
1736+
select 1 as a;
1737+
""")
1738+
1739+
audit_warning = "[WARNING] sqlmesh_example.full_model: 'full_nonblocking_audit' audit error: "
1740+
1741+
result = runner.invoke(
1742+
cli,
1743+
["--paths", str(tmp_path), "plan", "--no-prompts", "--auto-apply", "--skip-tests"],
1744+
)
1745+
assert result.exit_code == 0
1746+
assert audit_warning in result.output
1747+
1748+
result = runner.invoke(
1749+
cli,
1750+
[
1751+
"--ignore-warnings",
1752+
"--paths",
1753+
str(tmp_path),
1754+
"plan",
1755+
"--no-prompts",
1756+
"--auto-apply",
1757+
"--skip-tests",
1758+
],
1759+
)
1760+
assert result.exit_code == 0
1761+
assert audit_warning not in result.output

0 commit comments

Comments
 (0)