question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Django backend and gettext wrapper problem

See original GitHub issue

If I send message with subject wrapped into ugettext_lazy, PostMark backend falls down with the following error:

...
  File "/usr/local/lib/python2.7/site-packages/postmark/core.py", line 44, in default
    return super(PMJSONEncoder, self).default(o)
  File "/usr/local/lib/python2.7/site-packages/simplejson/encoder.py", line 252, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <django.utils.functional.__proxy__ object at 0x7f35c0e1fa10> is not JSON serializable

I’ve solved this bug locally with subject=str(subject). I think the best solution may be wrap subject and message body into str.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sjoerdjobcommented, Oct 31, 2018

I bumped into this.

Use-case: several views that send an e-mail, and have the “subject” of such a mail in a class-level attribute instead of inside a function.

Also, it’s clear that it was intended to be supported.

Solution would be I think to either remove the custom encoder and explicitly not support it, or to patch the encoder to fully support the latest version of Django, by checking __text_cast.

0reactions
nicholasserracommented, Nov 17, 2018

Thanks @sjoerdjob! If or when we fix this i’ll be referencing your details here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

django-admin makemessages --no-obsolete doesn't seem to ...
I ran makemessages command; It wrote a .po file as expected; Then I deleted gettext() line from view and saved file, verified runserver ......
Read more >
Translation | Django documentation
Since string extraction is done by the xgettext command, only syntaxes supported by gettext are supported by Django. In particular, Python f-strings are...
Read more >
Chapter 19: Internationalization - The Django Book
In this example, ugettext_lazy() stores a lazy reference to the string – not the actual translation. The translation itself will be done when...
Read more >
Django i18n: A beginner's guide - Lokalise Blog
The gettext module is available for you to use only through the backend in Python; therefore, it is not possible for you to...
Read more >
Django internationalization (i18n) tutorial - Localizely
django -admin startproject django_i18n_example ... Gettext is used by Django under the hood for all commands around the PO files that we will ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found