Skip to content

[Bug]: Check return type argument causing broken response on create_notification #21

Closed
@luqmansen

Description

@luqmansen

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?

  1. Using onesignal-python-api 2.0.0
  2. 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
            )
  1. 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.

if issubclass(oneof_class, ModelSimple):
if constant_kwargs.get('_spec_property_naming'):
oneof_instance = oneof_class._from_openapi_data(
model_arg, **constant_kwargs)
else:
oneof_instance = oneof_class(model_arg, **constant_kwargs)
elif oneof_class in PRIMITIVE_TYPES:
oneof_instance = validate_and_convert_types(
model_arg,
(oneof_class,),
constant_kwargs['_path_to_item'],
constant_kwargs['_spec_property_naming'],
constant_kwargs['_check_type'],
configuration=constant_kwargs['_configuration']
)
oneof_instances.append(oneof_instance)
except Exception:
pass
.

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    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