sklarsa / django-sendgrid-v5

An implementation of Django's EmailBackend compatible with sendgrid-python v5+
MIT License
323 stars 54 forks source link

Compatibility with django lazy-translated strings #19

Closed edevil closed 6 years ago

edevil commented 6 years ago

Related issue in a similar module: https://github.com/elbuo8/sendgrid-django/issues/66

When we include lazily translated strings in an email message we get errors like:

/usr/local/lib/python3.6/site-packages/sendgrid_backend/mail.py in send_messages(self, email_messages)
     64
     65             try:
---> 66                 self.sg.client.mail.send.post(request_body=data)
     67                 success += 1
     68             except HTTPError:

/usr/local/lib/python3.6/site-packages/python_http_client/client.py in http_request(*_, **kwargs)
    215                             data = json.dumps(kwargs['request_body']).encode('utf-8')
    216                     else:
--> 217                         data = json.dumps(kwargs['request_body']).encode('utf-8')
    218                 params = kwargs['query_params'] if 'query_params' in kwargs else None
    219                 opener = urllib.build_opener()

/usr/local/lib/python3.6/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
    229         cls is None and indent is None and separators is None and
    230         default is None and not sort_keys and not kw):
--> 231         return _default_encoder.encode(obj)
    232     if cls is None:
    233         cls = JSONEncoder

/usr/local/lib/python3.6/json/encoder.py in encode(self, o)
    197         # exceptions aren't as detailed.  The list call should be roughly
    198         # equivalent to the PySequence_Fast that ''.join() would do.
--> 199         chunks = self.iterencode(o, _one_shot=True)
    200         if not isinstance(chunks, (list, tuple)):
    201             chunks = list(chunks)

/usr/local/lib/python3.6/json/encoder.py in iterencode(self, o, _one_shot)
    255                 self.key_separator, self.item_separator, self.sort_keys,
    256                 self.skipkeys, _one_shot)
--> 257         return _iterencode(o, 0)
    258
    259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,

/usr/local/lib/python3.6/json/encoder.py in default(self, o)
    178         """
    179         raise TypeError("Object of type '%s' is not JSON serializable" %
--> 180                         o.__class__.__name__)
    181
    182     def encode(self, o):
sklarsa commented 6 years ago

This looks like an upstream problem in the sendgrid/python library. I don't think this API is the right layer to correct this bug. I would make a PR patching this in python/sendgrid, and upgrade that dependency accordingly once it's been approved.