jazzband / django-push-notifications

Send push notifications to mobile devices through GCM or APNS in Django.
MIT License
2.24k stars 609 forks source link

Passing badge parameter to bulk send_message breaks #606

Closed rollue closed 3 years ago

rollue commented 3 years ago

I tried sending messages in bulk as described in the doc

devices.send_message(
        "Happy name day!",
        badge=lambda token: APNSDevice.objects.get(registration_id=token).user.get_badge()
)

But I get TypeError: Object of type function is not JSON serializable error on line 152 in gcm.py where it says

...
json_payload = json.dumps(payload, separators=(",", ":"), sort_keys=True).encode("utf-8")
...

the payload that is used as a parameter to the json.dumps is as follows:

{  
  'registration_ids': ['some value.....'], 
  'notification': {'body': {'title': 'title..........', 'body': '.......'}, 
  'badge': <function ParticipationRequestWriteSerializer._record_notifications.<locals>.<lambda> at 0x10c2d00d0>}
}

It seems the lambda function that is passed as a keyword param(=badge) is not returning the value, but stays as a raw method. Any ideas?

rollue commented 3 years ago

GCMDevice does not support bulk send_message. I think this ought to be in the doc.

See my comment in https://github.com/jazzband/django-push-notifications/issues/477

Closing the issue as it's a duplicate.