11add5
From 855dc43e6f22c362a055b306b40cc91b843c7cb3 Mon Sep 17 00:00:00 2001
11add5
From: Adam Williamson <awilliam@redhat.com>
11add5
Date: Mon, 24 Jun 2024 12:10:47 -0700
11add5
Subject: [PATCH] Base64IO: set write buffer before doing attr check
11add5
11add5
TestBase64IO.test_init_fails() fails in current Fedora Rawhide
11add5
(with Python 3.13) because pytest complains about an unraisable
11add5
exception:
11add5
11add5
AttributeError: 'Base64IO' object has no attribute '_Base64IO__write_buffer'
11add5
11add5
it seems like we're reaching `close()` (via `__exit__()`, I
11add5
guess) even after raising an exception in `__init__()`, and that
11add5
causes a problem because we never set `self.__write_buffer` if
11add5
the required attrs check fails.
11add5
11add5
To solve this, we can just set `self.__write_buffer` before doing
11add5
the attr check.
11add5
11add5
Signed-off-by: Adam Williamson <awilliam@redhat.com>
11add5
---
11add5
 src/ansible_runner/utils/base64io.py | 4 +++-
11add5
 1 file changed, 3 insertions(+), 1 deletion(-)
11add5
11add5
diff --git a/src/ansible_runner/utils/base64io.py b/src/ansible_runner/utils/base64io.py
11add5
index 0a2422f..d9cf927 100644
11add5
--- a/src/ansible_runner/utils/base64io.py
11add5
+++ b/src/ansible_runner/utils/base64io.py
11add5
@@ -78,6 +78,9 @@ class Base64IO(io.IOBase):
11add5
 
11add5
         :raises TypeError: if ``wrapped`` does not have attributes needed to determine the stream's state
11add5
         """
11add5
+        # set before the attr check as we may reach close() after that
11add5
+        # check fails
11add5
+        self.__write_buffer = b""
11add5
         required_attrs = ("read", "write", "close", "closed", "flush")
11add5
         if not all(hasattr(wrapped, attr) for attr in required_attrs):
11add5
             raise TypeError(
11add5
@@ -86,7 +89,6 @@ class Base64IO(io.IOBase):
11add5
         super().__init__()
11add5
         self.__wrapped = wrapped
11add5
         self.__read_buffer = b""
11add5
-        self.__write_buffer = b""
11add5
 
11add5
     def __enter__(self):
11add5
         """Return self on enter."""
11add5
-- 
11add5
2.45.2
11add5