[python] Encode list query params (#20148)

* Bugfix: #17688: Encode list query params

* Test: #17688: Update validation error message tests for Pydantic 2.10+

Pydantic 2.10+ introduced changes to validation error messages,
requiring updates to the affected test cases.
This commit is contained in:
jops-wtakase 2024-11-27 00:53:12 +09:00 committed by GitHub
parent 7072009ab5
commit 7b35613cfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 12 additions and 7 deletions

View File

@ -525,7 +525,7 @@ class ApiClient:
if k in collection_formats: if k in collection_formats:
collection_format = collection_formats[k] collection_format = collection_formats[k]
if collection_format == 'multi': if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v) new_params.extend((k, quote(str(value))) for value in v)
else: else:
if collection_format == 'ssv': if collection_format == 'ssv':
delimiter = ' ' delimiter = ' '

View File

@ -518,7 +518,7 @@ class ApiClient:
if k in collection_formats: if k in collection_formats:
collection_format = collection_formats[k] collection_format = collection_formats[k]
if collection_format == 'multi': if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v) new_params.extend((k, quote(str(value))) for value in v)
else: else:
if collection_format == 'ssv': if collection_format == 'ssv':
delimiter = ' ' delimiter = ' '

View File

@ -518,7 +518,7 @@ class ApiClient:
if k in collection_formats: if k in collection_formats:
collection_format = collection_formats[k] collection_format = collection_formats[k]
if collection_format == 'multi': if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v) new_params.extend((k, quote(str(value))) for value in v)
else: else:
if collection_format == 'ssv': if collection_format == 'ssv':
delimiter = ' ' delimiter = ' '

View File

@ -520,7 +520,7 @@ class ApiClient:
if k in collection_formats: if k in collection_formats:
collection_format = collection_formats[k] collection_format = collection_formats[k]
if collection_format == 'multi': if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v) new_params.extend((k, quote(str(value))) for value in v)
else: else:
if collection_format == 'ssv': if collection_format == 'ssv':
delimiter = ' ' delimiter = ' '

View File

@ -517,7 +517,7 @@ class ApiClient:
if k in collection_formats: if k in collection_formats:
collection_format = collection_formats[k] collection_format = collection_formats[k]
if collection_format == 'multi': if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v) new_params.extend((k, quote(str(value))) for value in v)
else: else:
if collection_format == 'ssv': if collection_format == 'ssv':
delimiter = ' ' delimiter = ' '

View File

@ -294,3 +294,8 @@ class ApiClientTests(unittest.TestCase):
params = self.api_client.parameters_to_url_query(params=[('list', [1, 2, 3])], params = self.api_client.parameters_to_url_query(params=[('list', [1, 2, 3])],
collection_formats={'list': 'multi'}) collection_formats={'list': 'multi'})
self.assertEqual(params, "list=1&list=2&list=3") self.assertEqual(params, "list=1&list=2&list=3")
def test_parameters_to_url_query_list_value_encoded(self):
params = self.api_client.parameters_to_url_query(params=[('list', [" !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "2023-01-01T00:00:00+01:00"])],
collection_formats={'list': 'multi'})
self.assertEqual(params, "list=%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-./%3A%3B%3C%3D%3E%3F%40%5B%5C%5D%5E_%60%7B%7C%7D~&list=2023-01-01T00%3A00%3A00%2B01%3A00")

View File

@ -50,7 +50,7 @@ class ApiExceptionTests(unittest.TestCase):
try: try:
self.pet_api.get_pet_by_id() # type: ignore self.pet_api.get_pet_by_id() # type: ignore
except ValidationError as e: except ValidationError as e:
self.assertIn("1 validation error for get_pet_by_id", str(e)) self.assertIn("1 validation error for PetApi.get_pet_by_id", str(e))
self.assertIn("Missing required argument", str(e)) self.assertIn("Missing required argument", str(e))
def test_integer_validation(self): def test_integer_validation(self):
@ -61,7 +61,7 @@ class ApiExceptionTests(unittest.TestCase):
# pet_id # pet_id
# Input should be a valid integer [type=int_type, input_value='123', input_type=str] # Input should be a valid integer [type=int_type, input_value='123', input_type=str]
# For further information visit https://errors.pydantic.dev/2.3/v/int_type # For further information visit https://errors.pydantic.dev/2.3/v/int_type
self.assertIn("1 validation error for get_pet_by_id", str(e)) self.assertIn("1 validation error for PetApi.get_pet_by_id", str(e))
self.assertIn("Input should be a valid integer", str(e)) self.assertIn("Input should be a valid integer", str(e))
def test_string_enum_validation(self): def test_string_enum_validation(self):