Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sqlmesh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion sqlmesh/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion sqlmesh/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
53 changes: 53 additions & 0 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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