Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 🔧 fix Zappa.create_handler_venv win32 case wherestderror_result is None #1353

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2634,6 +2634,28 @@ def test_wsgi_query_string_with_encodechars(self):
expected = "query=Jane%26John&otherquery=B&test=hello%2Bm.te%26how%26are%26you"
self.assertEqual(request["QUERY_STRING"], expected)

@mock.patch("subprocess.Popen")
def test_create_handler_venv_win32_none_stderror_result(self, popen_mock):
class PopenMock:
returncode = 999

@classmethod
def communicate(cls):
return "valid_stdout", None # On win32, stderr can be None

popen_mock.return_value = PopenMock

boto_mock = mock.MagicMock()
zappa_core = Zappa(
boto_session=boto_mock,
profile_name="test",
aws_region="test",
load_credentials=True,
)

with self.assertRaises(EnvironmentError):
zappa_core.create_handler_venv()


if __name__ == "__main__":
unittest.main()
6 changes: 3 additions & 3 deletions zappa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def __init__(
self.manylinux_wheel_file_match = re.compile(
rf'^.*{self.manylinux_suffix_start}-(manylinux_\d+_\d+_x86_64[.])?manylinux({"|".join(self.manylinux_suffixes)})_x86_64[.]whl$' # noqa: E501
)
self.manylinux_wheel_abi3_file_match = re.compile(rf"^.*cp3.-abi3-manylinux.*_x86_64[.]whl$")
self.manylinux_wheel_abi3_file_match = re.compile(r"^.*cp3.-abi3-manylinux.*_x86_64[.]whl$")

self.endpoint_urls = endpoint_urls
self.xray_tracing = xray_tracing
Expand Down Expand Up @@ -488,9 +488,9 @@ def create_handler_venv(self, use_zappa_release: Optional[str] = None):

if pip_return_code:
logger.info("command: %s", " ".join(command))
if stdout_result.strip():
if stdout_result and stdout_result.strip():
logger.info("stdout: %s", stdout_result.strip())
if stderror_result.strip():
if stderror_result and stderror_result.strip():
logger.error("stderr: %s", stderror_result)
raise EnvironmentError("Pypi lookup failed")

Expand Down
4 changes: 2 additions & 2 deletions zappa/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ def encode_response(status, headers, exc_info=None):
Related: https://github.com/Miserlou/Zappa/issues/1965
"""

new_headers = [header for header in headers if ((type(header[0]) != str) or (header[0].lower() != "set-cookie"))]
new_headers = [header for header in headers if isinstance(header[0], str) or header[0].lower() != "set-cookie"]
cookie_headers = [
(header[0].lower(), header[1])
for header in headers
if ((type(header[0]) == str) and (header[0].lower() == "set-cookie"))
if isinstance(header[0], str) and header[0].lower() == "set-cookie"
]
new_headers = new_headers + cookie_headers

Expand Down
Loading