Skip to content

Fix notification_types type of SubscriptionObject model #48

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tonypizzicato
Copy link

@tonypizzicato tonypizzicato commented May 14, 2025

Description

Creating SubscriptionObject with notification_types value set (1, -31, etc) for the update_subscription fails with onesignal.exceptions.ApiTypeError: Invalid type for variable 'notification_types'. Required value type is float and passed type was int at ['notification_types'].

Details

Motivation

OneSignal API requires notification_types object of SubscriptionObject to be of type int and fails otherwise with {"errors":[{"title":"Field notification_types was expecting value of type 'int32', received value of type 'number 1.0' instead"}]}

Scope

notification_types type of SDK matches the type in the API.

The workaround could be to omit type check on the model creation step:

subscription=SubscriptionObject(
    id=sub['id'],
    enabled=enabled,
    notification_types=1 if enabled else -31,
    _check_type=False,
)

Testing

Manual testing

update_subscription_request_body = UpdateSubscriptionRequestBody(
    subscription=SubscriptionObject(
        id=sub['id'],
        enabled=enabled,
        notification_types=1 if enabled else -31,
    ),
)

api_instance.update_subscription(app_id, sub['id'], update_subscription_request_body)

fails with the following:

`onesignal.exceptions.ApiTypeError: Invalid type for variable 'notification_types'. Required value type is float and passed type was int at ['notification_types']`

Using floats with notification_types=1.0 if enabled else -31.0, instead fails on the API side with

 `{"errors":[{"title":"Field notification_types was expecting value of type 'int32', received value of type 'number 1.0' instead"}]}`

#46

@sherwinski
Copy link
Contributor

Hi @tonypizzicato and thanks for opening this PR! Unfortunately, the code for this library (and others like it) are autogenerated by an upstream project. For that reason, someone from our team will need to make the change there so that it will be added downstream. I'll keep you updated on our progress here or on #46.

Please let me know if you have any questions in the meantime.

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

Successfully merging this pull request may close these issues.

2 participants