BUG - <AdGroup for Retargeting Campaign Throws Value Error on init>
@dfana01 is already working on this.
Since Mar 20, 2025.
Assessment
This issue has not been assessed yet.
Description
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:
- The model/class with an issue is 'ads.ad_groups'
- 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
-
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 -
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:
Change we made to get the expected result correctly (added dict)
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
- Dominant language
- Python
- Stars
- 85
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pinterest/pinterest-python-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
-
AttributeError: 'BoardSection' object has no attribute '_generated_api_get_fn_args'May be free again @dfana01 claimed this 569 days ago, and no pull request is open. Openbug
pinterest/pinterest-python-sdk#130 · 1 assignee ·
-
BUG - SDK Client pin creation fails but endpoint is workingMay be free again @dfana01 claimed this 569 days ago, and no pull request is open. Openbug
pinterest/pinterest-python-sdk#128 · 1 comment · 1 assignee ·
All issues in pinterest/pinterest-python-sdk
Similar issues
-
area:space-accuracy good first issue track:data
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Sara-Managed-Projects/space-radar#904 ·
Maintainers usually reply within 1 day