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

Error: Invalid inputs given to generate an instance of 'Token' #94

Open
gsbiel opened this issue Aug 6, 2023 · 2 comments
Open

Error: Invalid inputs given to generate an instance of 'Token' #94

gsbiel opened this issue Aug 6, 2023 · 2 comments

Comments

@gsbiel
Copy link

gsbiel commented Aug 6, 2023

Version

fastly==4.0.0

What happened

I got an error while trying to list all tokens belonging to a customer.

In order to get started, I used the sample script provided here: https://github.com/fastly/fastly-py/blob/main/docs/TokensApi.md#list_tokens_customer

But when I tested it, I got the following error:

Traceback (most recent call last):
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1784, in get_allof_instances
    allof_instance = allof_class._from_openapi_data(**model_args, **constant_args)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 45, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model/token.py", line 183, in _from_openapi_data
    setattr(self, var_name, var_value)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 184, in __setattr__
    self[attr] = value
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 509, in __setitem__
    self.set_attribute(name, value)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 160, in set_attribute
    check_allowed_values(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 872, in check_allowed_values
    raise ApiValueError(
fastly.exceptions.ApiValueError: Invalid value for `scope` (global:read global), must be one of ['global', 'purge_select', 'purge_all', 'global:read']

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/gasper/Documents/work/experiments/audit_fastly_users/main.py", line 64, in <module>
    main()
  File "/home/gasper/Documents/work/experiments/audit_fastly_users/main.py", line 45, in main
    customer_tokens = list_customer_tokens(fastly_api_key, customer_id)
  File "/home/gasper/Documents/work/experiments/audit_fastly_users/main.py", line 32, in list_customer_tokens
    api_response = api_instance.list_tokens_customer(customer_id)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api/tokens_api.py", line 850, in list_tokens_customer
    return self.list_tokens_customer_endpoint.call_with_http_info(**kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api_client.py", line 872, in call_with_http_info
    return self.api_client.call_api(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api_client.py", line 427, in call_api
    return self.__call_api(resource_path, method,
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api_client.py", line 236, in __call_api
    return_data = self.deserialize(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api_client.py", line 341, in deserialize
    deserialized_data = validate_and_convert_types(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1619, in validate_and_convert_types
    input_value[index] = validate_and_convert_types(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1569, in validate_and_convert_types
    converted_instance = attempt_convert_item(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1462, in attempt_convert_item
    raise conversion_exc
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1453, in attempt_convert_item
    return deserialize_model(input_value, valid_class,
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1373, in deserialize_model
    return model_class._new_from_openapi_data(**kw_args)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 45, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 369, in _new_from_openapi_data
    return cls._from_openapi_data(*args, **kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 45, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model/token_response.py", line 223, in _from_openapi_data
    composed_info = validate_get_composed_info(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1992, in validate_get_composed_info
    allof_instances = get_allof_instances(self, model_args, constant_args)
  File "/home/gasper/.local/lib/python3.10/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 'Token'. The input data was invalid for the allOf schema 'Token' in the composed schema 'TokenResponse'. Error=Invalid value for `scope` (global:read global), must be one of ['global', 'purge_select', 'purge_all', 'global:read']

I was expecting to get a list containing all tokens belonging to my customer account.
Am I missing something? Can you folks help me to understand that error?

Any support would be highly appreciated!
Thank you!

@Integralist
Copy link
Collaborator

Hi @gsbiel

Thanks for raising this issue. Looks like there's a problem with the code-generation process for this API client.

The error is:

fastly.exceptions.ApiValueError: Invalid value for `scope` (global:read global), must be one of ['global', 'purge_select', 'purge_all', 'global:read']

Looking at the documented API https://developer.fastly.com/reference/api/auth-tokens/user/#data-model it seems scope can be assigned a "space-delimited list of authorization scope", which it is in your case (based on the error: it's set to global:read global) but the generated code for the API client thinks that it should be a single value (based on the error: must be one of ['global', 'purge_select', 'purge_all', 'global:read']).

I'll open a ticket internally to track this.

@gsbiel
Copy link
Author

gsbiel commented Aug 7, 2023

Hi @Integralist
Thank you very much for your support on this :)

I tried to workaround that error by configuring my Fastly API key to have only a single value as scope, but no success.
In that case, I setup only global:read scope, but got another error:

Traceback (most recent call last):
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1784, in get_allof_instances
    allof_instance = allof_class._from_openapi_data(**model_args, **constant_args)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 45, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model/token_response_all_of.py", line 191, in _from_openapi_data
    setattr(self, var_name, var_value)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 184, in __setattr__
    self[attr] = value
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 509, in __setitem__
    self.set_attribute(name, value)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 156, in set_attribute
    value = validate_and_convert_types(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1569, in validate_and_convert_types
    converted_instance = attempt_convert_item(
  File "/home/gasper/.local/lib/python3.10/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 'expires_at'. Required value type is str and passed type was NoneType at ['received_data'][0]['expires_at']

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/gasper/Documents/hearst/experiments/audit_fastly_users/main.py", line 74, in <module>
    main()
  File "/home/gasper/Documents/hearst/experiments/audit_fastly_users/main.py", line 54, in main
    customer_tokens = list_customer_tokens(fastly_api_key, customer_id)
  File "/home/gasper/Documents/hearst/experiments/audit_fastly_users/main.py", line 33, in list_customer_tokens
    api_response = api_instance.list_tokens_customer(customer_id)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api/tokens_api.py", line 850, in list_tokens_customer
    return self.list_tokens_customer_endpoint.call_with_http_info(**kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api_client.py", line 872, in call_with_http_info
    return self.api_client.call_api(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api_client.py", line 427, in call_api
    return self.__call_api(resource_path, method,
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api_client.py", line 236, in __call_api
    return_data = self.deserialize(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/api_client.py", line 341, in deserialize
    deserialized_data = validate_and_convert_types(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1619, in validate_and_convert_types
    input_value[index] = validate_and_convert_types(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1569, in validate_and_convert_types
    converted_instance = attempt_convert_item(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1462, in attempt_convert_item
    raise conversion_exc
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1453, in attempt_convert_item
    return deserialize_model(input_value, valid_class,
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1373, in deserialize_model
    return model_class._new_from_openapi_data(**kw_args)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 45, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 369, in _new_from_openapi_data
    return cls._from_openapi_data(*args, **kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 45, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model/token_response.py", line 223, in _from_openapi_data
    composed_info = validate_get_composed_info(
  File "/home/gasper/.local/lib/python3.10/site-packages/fastly/model_utils.py", line 1992, in validate_get_composed_info
    allof_instances = get_allof_instances(self, model_args, constant_args)
  File "/home/gasper/.local/lib/python3.10/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 'TokenResponseAllOf'. The input data was invalid for the allOf schema 'TokenResponseAllOf' in the composed schema 'TokenResponse'. Error=Invalid type for variable 'expires_at'. Required value type is str and passed type was NoneType at ['received_data'][0]['expires_at']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants