From 876e563680f606858e11117f1231c4e4c43824c9 Mon Sep 17 00:00:00 2001 From: Trey Spiller Date: Fri, 9 May 2025 11:48:18 -0500 Subject: [PATCH 1/2] Make logger respect --ignore-warnings --- sqlmesh/__init__.py | 3 ++- sqlmesh/cli/main.py | 8 +++++++- sqlmesh/magics.py | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sqlmesh/__init__.py b/sqlmesh/__init__.py index a033b652d7..e48ffbef5b 100644 --- a/sqlmesh/__init__.py +++ b/sqlmesh/__init__.py @@ -172,6 +172,7 @@ def configure_logging( write_to_file: bool = True, log_limit: int = c.DEFAULT_LOG_LIMIT, log_file_dir: t.Optional[t.Union[str, Path]] = None, + ignore_warnings: bool = False, ) -> None: # Remove noisy grpc logs that are not useful for users os.environ["GRPC_VERBOSITY"] = os.environ.get("GRPC_VERBOSITY", "NONE") @@ -186,7 +187,7 @@ def configure_logging( if write_to_stdout: stdout_handler = logging.StreamHandler(sys.stdout) stdout_handler.setFormatter(CustomFormatter()) - stdout_handler.setLevel(level) + stdout_handler.setLevel(logging.ERROR if ignore_warnings else level) logger.addHandler(stdout_handler) log_file_dir = log_file_dir or c.DEFAULT_LOG_FILE_DIR diff --git a/sqlmesh/cli/main.py b/sqlmesh/cli/main.py index c60506d023..14b9ebd42c 100644 --- a/sqlmesh/cli/main.py +++ b/sqlmesh/cli/main.py @@ -102,7 +102,13 @@ def cli( configs = load_configs(config, Context.CONFIG_TYPE, paths) log_limit = list(configs.values())[0].log_limit - configure_logging(debug, log_to_stdout, log_limit=log_limit, log_file_dir=log_file_dir) + configure_logging( + debug, + log_to_stdout, + log_limit=log_limit, + log_file_dir=log_file_dir, + ignore_warnings=ignore_warnings, + ) configure_console(ignore_warnings=ignore_warnings) try: diff --git a/sqlmesh/magics.py b/sqlmesh/magics.py index d6e540357c..313b98ab52 100644 --- a/sqlmesh/magics.py +++ b/sqlmesh/magics.py @@ -134,7 +134,12 @@ def context(self, line: str) -> None: args = parse_argstring(self.context, line) configs = load_configs(args.config, Context.CONFIG_TYPE, args.paths) log_limit = list(configs.values())[0].log_limit - configure_logging(args.debug, log_limit=log_limit, log_file_dir=args.log_file_dir) + configure_logging( + args.debug, + log_limit=log_limit, + log_file_dir=args.log_file_dir, + ignore_warnings=args.ignore_warnings, + ) configure_console(ignore_warnings=args.ignore_warnings) try: context = Context(paths=args.paths, config=configs, gateway=args.gateway) From 91eea5966d316d7c0cc3f04b04ade3b6735ae0dd Mon Sep 17 00:00:00 2001 From: Trey Spiller Date: Fri, 9 May 2025 14:22:30 -0500 Subject: [PATCH 2/2] Add test --- tests/cli/test_cli.py | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index eaaa04017c..c0b1722c06 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -1706,3 +1706,56 @@ def test_dbt_init(tmp_path): config = sqlmesh_config(Path(__file__).parent) """ ) + + +def test_ignore_warnings(runner: CliRunner, tmp_path: Path) -> None: + create_example_project(tmp_path) + + # Add non-blocking audit to generate WARNING + with open(tmp_path / "models" / "full_model.sql", "w", encoding="utf-8") as f: + f.write(""" +MODEL ( + name sqlmesh_example.full_model, + kind FULL, + cron '@daily', + grain item_id, + audits (full_nonblocking_audit), +); + +SELECT + item_id, + COUNT(DISTINCT id) AS num_orders, +FROM + sqlmesh_example.incremental_model +GROUP BY item_id; + +AUDIT ( + name full_nonblocking_audit, + blocking false, +); +select 1 as a; +""") + + audit_warning = "[WARNING] sqlmesh_example.full_model: 'full_nonblocking_audit' audit error: " + + result = runner.invoke( + cli, + ["--paths", str(tmp_path), "plan", "--no-prompts", "--auto-apply", "--skip-tests"], + ) + assert result.exit_code == 0 + assert audit_warning in result.output + + result = runner.invoke( + cli, + [ + "--ignore-warnings", + "--paths", + str(tmp_path), + "plan", + "--no-prompts", + "--auto-apply", + "--skip-tests", + ], + ) + assert result.exit_code == 0 + assert audit_warning not in result.output