From 068fbf8cd2c6c6e522f0d328206d9d152b603342 Mon Sep 17 00:00:00 2001 From: peterstone2017 <12449837+YunchuWang@users.noreply.github.com> Date: Tue, 26 Jul 2022 16:38:26 -0500 Subject: [PATCH] cookies get key hotfix (#1076) Co-authored-by: peterstone2017 --- azure_functions_worker/bindings/datumdef.py | 2 +- tests/unittests/test_datumref.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/azure_functions_worker/bindings/datumdef.py b/azure_functions_worker/bindings/datumdef.py index 8449219d..3600c376 100644 --- a/azure_functions_worker/bindings/datumdef.py +++ b/azure_functions_worker/bindings/datumdef.py @@ -192,7 +192,7 @@ def datum_as_proto(datum: Datum) -> protos.TypedData: k: v.value for k, v in datum.value['headers'].items() }, - cookies=parse_to_rpc_http_cookie_list(datum.value['cookies']), + cookies=parse_to_rpc_http_cookie_list(datum.value.get('cookies')), enable_content_negotiation=False, body=datum_as_proto(datum.value['body']), )) diff --git a/tests/unittests/test_datumref.py b/tests/unittests/test_datumref.py index 62768592..2d9ecb7f 100644 --- a/tests/unittests/test_datumref.py +++ b/tests/unittests/test_datumref.py @@ -9,7 +9,7 @@ from dateutil.parser import ParserError from azure_functions_worker import protos from azure_functions_worker.bindings.datumdef import \ parse_cookie_attr_expires, \ - parse_cookie_attr_same_site, parse_to_rpc_http_cookie_list + parse_cookie_attr_same_site, parse_to_rpc_http_cookie_list, Datum from azure_functions_worker.bindings.nullable_converters import \ to_nullable_bool, to_nullable_string, to_nullable_double, \ to_nullable_timestamp @@ -127,3 +127,16 @@ class TestDatumRef(unittest.TestCase): rpc_cookies = parse_to_rpc_http_cookie_list([cookies]) self.assertEqual(cookie1, rpc_cookies[0]) self.assertEqual(cookie2, rpc_cookies[1]) + + def test_parse_to_rpc_http_cookie_list_no_cookie(self): + datum = Datum( + type='http', + value=dict( + status_code=None, + headers=None, + body=None, + ) + ) + + self.assertIsNone( + parse_to_rpc_http_cookie_list(datum.value.get('cookies')))