Description
What happened?
When calling create_notification
with all kwargs defaulted, it will result in {}
response because the serializer model failed to serialize the response.
The default value for _check_return_type
is True, which will check for returned type from the server.
This is the expected class of the response
class CreateNotificationSuccessResponse:
id: str
recipients: int
external_id: (str, none_type)
errors: Notification200Errors
This is the Notification200Errors
class
class Notification200Errors:
oneOf: [InvalidIdentifierError, NoSubscribersError]
This is the possible composed class for Notification200Errors
class InvalidIdentifierError:
invalid_external_user_ids: [str]
invalid_player_ids': [str]
class NoSubscribersError:
value: [str]
This is what returned from the server
{
"id": "",
"errors": ["All included players are not subscribed"]
}
The errors
key didn't follow the defined schema, thus it broke the code.
onesignal.exceptions.ApiTypeError: Invalid type for variable 'value'. Required value type is list and passed type was str at ['received_data']['errors']['value']
Steps to reproduce?
- Using onesignal-python-api 2.0.0
- Create the notification using sdk, specify destination to an unsubscribed user, or a non-existent user
with onesignal.ApiClient(configuration) as api_client:
api_instance = default_api.DefaultApi(api_client)
try:
response = api_instance.create_notification(
Notification(
include_external_user_ids=['destination'],
channel_for_external_user_ids='push',
headings=dict(en="subject"),
contents=dict(en="body"),
),
_check_return_type=True, # this is the default value
)
- The response will be
{}
What did you expect to happen?
The response should not be {}
when the server returned user unsubscribed
error.
This is (probably) what the deserializer expected from the server response
{
"id": "",
"errors": {
"value" : ["All included players are not subscribed"],
}
Checking at the code, seems like this exception is intentionally silenced.
onesignal-python-api/onesignal/model_utils.py
Lines 1872 to 1889 in f89f700
Relevant log output
No response
Code of Conduct
- I agree to follow this project's Code of Conduct