Skip to content
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

Having problem on django-mailer on using with djoser #144

Open
pawanpaudel93 opened this issue Jun 12, 2021 · 6 comments
Open

Having problem on django-mailer on using with djoser #144

pawanpaudel93 opened this issue Jun 12, 2021 · 6 comments
Labels

Comments

@pawanpaudel93
Copy link

I get the following error on using django-mailer with djoser on creation of users using the djoser. Seems that it is unable to pickle the request <rest_framework.request.Request: POST '/auth/users/'>.
image

@spookylukey
Copy link
Contributor

spookylukey commented Jun 13, 2021

It's not at all clear to me that this is a bug in django-mailer. It rather looks like a bug in "templated_mail" due to it creating EmailMessage objects in some non standard way that means they can't be pickled.

If you can provide a reduced test case that shows an issue in django-mailer that would be helpful.

@pawanpaudel93
Copy link
Author

@spookylukey thanks for replying.

This is what Djoser uses django-templated-mail and It works only when I remove the request https://github.com/pawanpaudel93/django-mailer/blob/master/src/mailer/models.py#L94 while pickling the email on django-mailer. So, there is a problem picking the request. Can you take a look at why the pickling error is occurring ?? @spookylukey

@spookylukey
Copy link
Contributor

OK, it's like I thought. templated_mail is adding extra stuff to the EmailMessage instances, things that can't be pickled (like HttpRequest objects). django-mailer needs to pickle the EmailMessage object, so that is incompatible.

See https://github.com/sunscrapers/django-templated-mail/blob/65e5a34f69d50d4d1b6acdd337f9efcc44b32fae/templated_mail/mail.py#L18

You need to file a bug with templated_mail and see if there is a way for them to do it without adding that attribute. There is no reason for EmailMessage objects to have the request attached to them, that's sounds like a bad design decision to me. An email class shouldn't have access to HttpRequest objects, it's a layering violation, because sending email has got nothing to do with processing HTTP requests. You should rather separate those activities - you should have a function/class that prepares the content of the email (which may use request if you really want), and then passes it on to the EmailMessage constructor. There is no need to subclass EmailMessage in this case.

@pawanpaudel93
Copy link
Author

@spookylukey Thank you very much for your time and help and also thanks for the great Django app.

@spookylukey
Copy link
Contributor

I'm going to re-open this, for the sake of anyone searching for the issue, although I don't intend to do anything about it in django-mailer itself.

@spookylukey
Copy link
Contributor

spookylukey commented Jun 27, 2021

See sunscrapers/django-templated-mail#29 which may resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants