From 172162d4f489ac6fde061cf9f99e7a3bec995072 Mon Sep 17 00:00:00 2001 From: Vinay Kumar Date: Thu, 29 Oct 2026 16:37:01 +0530 Subject: [PATCH] Fixes #1978: Bug: log_error ignores --quiet flag when stdout is redirected The issue was in the log_error method in httpie/context.py where the condition checked both self.stdout_isatty and self.quiet >= threshold. When stdout is redirected (not a TTY), self.stdout_isatty becomes False, which bypasses the quiet threshold check entirely. This meant that even with --quiet flag, warnings would still be printed to stderr when stdout was redirected. The fix removes self.stdout_isatty from the condition so that the logic mirrors apply_warnings_filter and properly respects the quiet flag regardless of whether stdout is a TTY or not. --- httpie/context.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/httpie/context.py b/httpie/context.py index 2a54f46916..c7567d1922 100644 --- a/httpie/context.py +++ b/httpie/context.py @@ -36,6 +36,7 @@ class LogLevel(str, Enum): LogLevel.ERROR: GenericColor.RED, } + LOG_LEVEL_DISPLAY_THRESHOLDS = { LogLevel.INFO: 1, LogLevel.WARNING: 2, @@ -168,7 +169,9 @@ def as_silent(self) -> Iterator[None]: self.stderr = original_stderr def log_error(self, msg: str, level: LogLevel = LogLevel.ERROR) -> None: - if self.stdout_isatty and self.quiet >= LOG_LEVEL_DISPLAY_THRESHOLDS[level]: + # FIXED: Removed self.stdout_isatty from condition + # This ensures that the quiet flag works correctly even when stdout is redirected + if self.quiet >= LOG_LEVEL_DISPLAY_THRESHOLDS[level]: stderr = self.stderr # Not directly /dev/null, since stderr might be mocked else: stderr = self._orig_stderr @@ -214,4 +217,4 @@ def rich_console(self): @cached_property def rich_error_console(self): - return self._make_rich_console(self.stderr, self.stderr_isatty) + return self._make_rich_console(self.stderr, self.stderr_isatty) \ No newline at end of file