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

Exception 'str' object has no attribute 'from_email' when calling Message.reply() #285

Closed
joshpark23 opened this issue Mar 13, 2024 · 8 comments

Comments

@joshpark23
Copy link

joshpark23 commented Mar 13, 2024

Issue description

When calling the reply() method on a Message instance, an exception is thrown with the message "'str' object has no attribute 'from_email'".

Proposed solution

Lines 658-662 in models.py, update implementation to avoid accessing the property not found on the Message model.
https://github.com/coddingtonbear/django-mailbox/blob/f4a0782d3df6fb54ce474448050764cc28b64ecd/django_mailbox/models.py#L658C1-L659C1

Note

This property is found on the mailbox model but not the message, not sure why it's being accessed here. Happy to raise the PR

@joshpark23 joshpark23 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2024
@pfouque
Copy link
Collaborator

pfouque commented Mar 14, 2024

Hi @joshpark23,
I was about to ask if you were properly calling this method with an instance of EmailMessage?
Did you find a solution?
Do you think something would help clarify the usage of that method?
Thanks

@joshpark23
Copy link
Author

Hey @pfouque appreciate the reply -- I wasn't passing an instance of EmailMessage to the reply method which was causing the error

Depending on any backwards compatibility requirements, adding type hints (>= python 3.5) could be helpful.
Something less breaking could be an update to the doc string specifying the expected type of the message param

@pfouque
Copy link
Collaborator

pfouque commented Mar 26, 2024

I like typing, but I'm not sure we are ready to do that.

Maybe adding a good old parameter check would have been enough.

        if not isinstance(message, EmailMessage):
            raise ValueError('Message must be an instance of EmailMessage')

@enaut
Copy link
Contributor

enaut commented May 22, 2024

Could someone provide me with a working example? I fail to get it to work:

from email.message import EmailMessage
from django_mailbox.models import Message
def signal_handler(sender, message, **args):
    rpl = Message( subject="pong",  body="pongpong" )
    message.reply(rpl)

I tried with EmailMessage but I cannot instantiate that and over all I'm confused.

@pfouque
Copy link
Collaborator

pfouque commented May 23, 2024

Hi @enaut,

Have you tried with Django's EmailMessage?

from django.core.mail import EmailMessage
from django_mailbox.models import Message

def signal_handler(sender, message, **args):
    rpl = EmailMessage( subject="pong",  body="pongpong" )
    message.reply(rpl)

@enaut
Copy link
Contributor

enaut commented May 23, 2024

Thank you! Sometimes I miss the obvious! VsCode did not suggest that import, so I was not aware it might exist…

@pfouque
Copy link
Collaborator

pfouque commented May 23, 2024

It means it wasn't obvious enough! ;)
We should improve the documentation of this function

@pfouque
Copy link
Collaborator

pfouque commented May 24, 2024

Adding this: #293
Feel free to comment!
I hope it will be more clear (after updating the documentation and releasing a new version)

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

No branches or pull requests

3 participants