Skip to content

BUG - <AdGroup for Retargeting Campaign Throws Value Error on init> #144

Open
@B-Liuh

Description

@B-Liuh

Describe the bug

Creating an instance of an AdGroup object with an adgroup ID under a retargeting campaign throws the error Invalid type for variable '0'. Required value type is TargetingSpecSHOPPINGRETARGETING and passed type was dict at ['shopping_retargeting'][0]

The open_api generated ad_group_response object has an issue with the allowed values for the 'targeting_spec` attribute

To Reproduce

Steps to reproduce the behavior:

  1. The model/class with an issue is 'ads.ad_groups'
  2. The function with an issue is __init__

Code that throws the exception

from pinterest.ads.ad_groups import AdGroup

ad_group_id = "{redacted id}"
account_id = "{redacted id}"

ad_group = AdGroup(account_id, ad_group_id)

Fails during the call to PinterestBaseModel.__init__ on the AdGroupResponse

  1. The arguments passed to the model/function are ' AccountID (str) and AdGroupID (str)'
    The adgroupID is from an adgroup that is a part of a retargeting campaign

  2. The error thrown is Invalid type for variable '0'. Required value type is TargetingSpecSHOPPINGRETARGETING and passed type was dict at ['shopping_retargeting'][0]

Expected behavior

When creating an AdGroup object, the get request to the API succeeds without throwing the value type error

targeting_spec attribute's expected type does not allow for dicts

Screenshots

The api call being made:
image

Change we made to get the expected result correctly (added dict)
image

Additional Details (please complete the following information):

  • OS and Version: MacOS
  • SDK Version 0.2.4

Additional Context

Full stack trace:

/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/bin/python /Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/test.py 
Traceback (most recent call last):
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/pinterest/utils/base_model.py", line 71, in _populate_fields
    attribute_value = (self._model_attribute_types.get(field)[0])(_model_data.get(field))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/openapi_generated/pinterest_client/model_utils.py", line 46, in wrapped_init
    return fn(_self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/openapi_generated/pinterest_client/model/targeting_spec.py", line 308, in __init__
    raise ApiTypeError(
openapi_generated.pinterest_client.exceptions.ApiTypeError: Invalid positional arguments=({'locale': ['ar', 'cs', 'da', 'de', 'el', 'en', 'es', 'fi', 'fr', 'he', 'hi', 'hu', 'id', 'it', 'ja', 'ko', 'ms', 'nb', 'nl', 'pl', 'pt', 'ro', 'ru', 'sk', 'sv', 'th', 'tl', 'tr', 'uk', 'vi', 'zh'], 'targeting_strategy': ['CHOOSE_YOUR_OWN'], 'shopping_retargeting': [{'lookback_window': 60, 'tag_types': [0, 6], 'exclusion_window': 0}], 'gender': ['unknown', 'male', 'female'], 'apptype': ['ipad', 'web', 'web_mobile', 'iphone', 'android_tablet', 'android_mobile'], 'location': ['US']},) passed to TargetingSpec. Remove those invalid positional arguments.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/test.py", line 29, in <module>
    ad_group = AdGroup(account_id, ad_group_id)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/pinterest/ads/ad_groups.py", line 80, in __init__
    self._populate_fields(**kwargs)
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/pinterest/utils/base_model.py", line 73, in _populate_fields
    attribute_value = (self._model_attribute_types.get(field)[0])(**_model_data.get(field))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/openapi_generated/pinterest_client/model_utils.py", line 46, in wrapped_init
    return fn(_self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/openapi_generated/pinterest_client/model/targeting_spec.py", line 331, in __init__
    setattr(self, var_name, var_value)
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/openapi_generated/pinterest_client/model_utils.py", line 185, in __setattr__
    self[attr] = value
    ~~~~^^^^^^
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/openapi_generated/pinterest_client/model_utils.py", line 510, in __setitem__
    self.set_attribute(name, value)
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/openapi_generated/pinterest_client/model_utils.py", line 157, in set_attribute
    value = validate_and_convert_types(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/openapi_generated/pinterest_client/model_utils.py", line 1620, in validate_and_convert_types
    input_value[index] = validate_and_convert_types(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rafigildiaz/Documents/github/pmg/solutions-social-consolidation/.venv/lib/python3.11/site-packages/openapi_generated/pinterest_client/model_utils.py", line 1582, in validate_and_convert_types
    raise get_type_error(input_value, path_to_item, valid_classes,
openapi_generated.pinterest_client.exceptions.ApiTypeError: Invalid type for variable '0'. Required value type is TargetingSpecSHOPPINGRETARGETING and passed type was dict at ['shopping_retargeting'][0]

Process finished with exit code 1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions