fastly-py
fastly-py copied to clipboard
ApiValueError BackendResponse Invalid type for variable prefer_ipv6
Version
fastly==9.0.0
What happened
Upgraded the Fastly package to the latest version and then received this error.
The function
with fastly.ApiClient(fastly_config) as api_client:
...
api_instance = backend_api.BackendApi(api_client)
...
api_response = api_instance.get_backend(service_id, version_number, backend_name)
send: b'GET /service/blaaa/version/125/backend/www_backend HTTP/1.1\r\nHost: api.fastly.com\r\nAccept-Encoding: identity\r\nAccept: application/json\r\nUser-Agent: fastly-py/9.0.0\r\nFastly-Key: blablabla\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Connection: keep-alive
header: Content-Length: 1066
header: Content-Type: application/json
header: status: 200 OK
header: Accept-Ranges: bytes
header: Via: 1.1 varnish, 1.1 varnish
header: Server: fastly
header: Date: Tue, 10 Jun 2025 07:46:55 GMT
header: X-Served-By: cache-chi-klot8100125-CHI, cache-sof1510027-SOF
header: X-Cache: MISS, MISS
header: X-Cache-Hits: 0, 0
header: X-Timer: S1749541616.626950,VS0,VE235
header: Vary: Accept-Encoding
header: Cache-Control: no-store
header: Pragma: no-cache
header: Strict-Transport-Security: max-age=31536000
Traceback (most recent call last):
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 1784, in get_allof_instances
allof_instance = allof_class._from_openapi_data(**model_args, **constant_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 45, in wrapped_init
return fn(_self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model/backend.py", line 280, in _from_openapi_data
setattr(self, var_name, var_value)
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 184, in __setattr__
self[attr] = value
~~~~^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 509, in __setitem__
self.set_attribute(name, value)
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 156, in set_attribute
value = validate_and_convert_types(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 1569, in validate_and_convert_types
converted_instance = attempt_convert_item(
^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 1448, in attempt_convert_item
raise get_type_error(input_value, path_to_item, valid_classes,
fastly.exceptions.ApiTypeError: Invalid type for variable 'prefer_ipv6'. Required value type is bool and passed type was NoneType at ['received_data']['prefer_ipv6']
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/somewhere/src/main.py", line 593, in <module>
fastly_payload: list[SpreadsheetDto] = extract_some_data(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/src/main.py", line 475, in extract_some_data
fastly_site_id = get_fastly_site_id(
^^^^^^^^^^^^^^^^^^^
File "/somewhere/src/main.py", line 383, in get_fastly_site_id
api_response = api_instance.get_backend(service_id, version_number, backend_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/api/backend_api.py", line 1090, in get_backend
return self.get_backend_endpoint.call_with_http_info(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/api_client.py", line 872, in call_with_http_info
return self.api_client.call_api(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/api_client.py", line 427, in call_api
return self.__call_api(resource_path, method,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/api_client.py", line 236, in __call_api
return_data = self.deserialize(
^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/api_client.py", line 341, in deserialize
deserialized_data = validate_and_convert_types(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 1569, in validate_and_convert_types
converted_instance = attempt_convert_item(
^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 1462, in attempt_convert_item
raise conversion_exc
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 1453, in attempt_convert_item
return deserialize_model(input_value, valid_class,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 1373, in deserialize_model
return model_class._new_from_openapi_data(**kw_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 45, in wrapped_init
return fn(_self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 369, in _new_from_openapi_data
return cls._from_openapi_data(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 45, in wrapped_init
return fn(_self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model/backend_response.py", line 314, in _from_openapi_data
composed_info = validate_get_composed_info(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 1992, in validate_get_composed_info
allof_instances = get_allof_instances(self, model_args, constant_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/somewhere/.venv/lib/python3.12/site-packages/fastly/model_utils.py", line 1789, in get_allof_instances
raise ApiValueError(
fastly.exceptions.ApiValueError: Invalid inputs given to generate an instance of 'Backend'. The input data was invalid for the allOf schema 'Backend' in the composed schema 'BackendResponse'. Error=Invalid type for variable 'prefer_ipv6'. Required value type is bool and passed type was NoneType at ['received_data']['prefer_ipv6']
https://github.com/fastly/fastly-py/blob/7c81eaafa501d462f4c676a3b079e0bc69a798ec/fastly/model/backend_response.py#L117
It seems that it should be able to be set as NoneType. We have not used this property from the UI, and some of our backend origins are over 2 years old.
This is a new property added recently to the Fastly platform, and all existing backends were set to none as part of the release. Unfortunately as you can see its type was incorrectly defined as boolean in our internal API schemas, which resulted in the generated API client having incorrect code. We'll get this fixed.