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

EnabledProductsApi TypeError #100

Open
findmyname666 opened this issue Apr 29, 2024 · 4 comments
Open

EnabledProductsApi TypeError #100

findmyname666 opened this issue Apr 29, 2024 · 4 comments

Comments

@findmyname666
Copy link

findmyname666 commented Apr 29, 2024

Version

Lib version: 5.2.0.

What happened

I tried to use Enable Product API but it is failing on type error when using multiple methods on instance class of EnabledProductsApi:

    api_response = api_instance.get_enabled_product(**options)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/api/enabled_products_api.py", line 471, in get_enabled_product
    return self.get_enabled_product_endpoint.call_with_http_info(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/api_client.py", line 872, in call_with_http_info
    return self.api_client.call_api(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/api_client.py", line 427, in call_api
    return self.__call_api(resource_path, method,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/api_client.py", line 236, in __call_api
    return_data = self.deserialize(
                  ^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/api_client.py", line 341, in deserialize
    deserialized_data = validate_and_convert_types(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 1569, in validate_and_convert_types
    converted_instance = attempt_convert_item(
                         ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 1453, in attempt_convert_item
    return deserialize_model(input_value, valid_class,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 1373, in deserialize_model
    return model_class._new_from_openapi_data(**kw_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 45, in wrapped_init
    return fn(_self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 369, in _new_from_openapi_data
    return cls._from_openapi_data(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 45, in wrapped_init
    return fn(_self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model/enabled_product_response.py", line 186, in _from_openapi_data
    setattr(self, var_name, var_value)
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 184, in __setattr__
    self[attr] = value
    ~~~~^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 509, in __setitem__
    self.set_attribute(name, value)
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 156, in set_attribute
    value = validate_and_convert_types(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 1569, in validate_and_convert_types
    converted_instance = attempt_convert_item(
                         ^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 1453, in attempt_convert_item
    return deserialize_model(input_value, valid_class,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 1373, in deserialize_model
    return model_class._new_from_openapi_data(**kw_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 45, in wrapped_init
    return fn(_self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/q9k17i98pxvzxxqk7mazb8gnbcpwffj9-python3-3.11.8-env/lib/python3.11/site-packages/fastly/model_utils.py", line 369, in _new_from_openapi_data
    return cls._from_openapi_data(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: EnabledProductResponseLinks._from_openapi_data() got multiple values for argument '_self'

The above error is raised also for python example code from the Fastly documentation.

@kpfleming
Copy link
Contributor

Please try to reproduce this with version 5.7.0 or later; if it's still an issue we'll try to get it resolved.

@NeevCohen
Copy link

NeevCohen commented Sep 20, 2024

Hey @kpfleming, I can confirm this issue still exists.
I looked into it a bit and the problem is the way wrapped_init changes the response json keys into python keys.

The enabled-product APIs return an object with a key named "self". In change_keys_js_to_python "self" is converted to "_self". This makes it so that fn is called with 2 _self arguments.

This is an example response from the API as per the documentation

{
  "product": {
    "id": "product-id",
    "object": "product"
  },
  "service": {
    "id": "4nWURjwmQjbMB5OefSM75i",
    "object": "service"
  },
  "_links": {
    "self": "https://api.fastly.com/enabled-products/v1/product-id/services/4nWURjwmQjbMB5OefSM75i",
    "service": "https://api.fastly.com/service/4nWURjwmQjbMB5OefSM75i"
  }
}

The "self" key in the _"links" object is turned into "_self", which is then forwarded to fn like so when deserializing it into the EnabledProductResponseLinks -

return fn(_self, *args, **kwargs)  # kwargs contains _self='...'

which causes the _self argument to be passed into fn multiple times.

I hope explained the issue clearly 😄

I don't mind opening a PR to fix this.
My first thought was to rename the _self variable to _self_ in order to overcome the name collision. WDYT?

@kpfleming
Copy link
Contributor

Thanks for finding the issue! We can't accept a PR directly against this repo as the code here is produced by a generator (in a private repository), but we can take these details and produce a fix for the generator.

@NeevCohen
Copy link

@kpfleming Happy to help!

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

3 participants