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.

Hooks returning None should make smtp.py behave like nothing happened.

See original GitHub issue

When hooks are called for each steps of the SMTP call, the code check if the MISSING value is returned, which is an instance of object().

I’m curious to know why.

From my perspective, if a call to a hook returns None, the code should continue like if there were no hooks at all. The reason behind that is if no response is returned from the hook, the server still has to return a status, and the default one is accepted by the developer.

Moreover, if a hook exists, it MUST implement the logics presents in smtp.py when no hooks exists. Let me explain:

Here’s the line for HELO commands

If there are no hooks, here’s what’s happening:

        status = await self._call_handler_hook('HELO', hostname)
        if status is MISSING:
            self.session.host_name = hostname
            status = '250 HELP'

But as soon as I add a HELO handler, the status won’t be MISSING, which means I have to implement the two consequent lines in my own code, by copy/pasting it. That’s not good.

Instead, if the smtp.py code does the following:

        status = await self._call_handler_hook('HELO', hostname)
        # This expect that the self._call_handler_hook returns also None in case no handler was found
        if status is None:
            self.session.host_name = hostname
            status = '250 HELP'

My handle can return None, saying “everything is good” like all hooks behave, and smtp.py will do the intended work.

But maybe I’m missing a specific reason, so I’d be curious to know.

Otherwise, happy to submit a PR if you want!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cnicodemecommented, Jan 7, 2021

My bad, I did meant #157 😉

0reactions
pepoluancommented, Feb 13, 2021

I actually have created a branch for this issue: https://github.com/pepoluan/aiosmtpd/tree/treat-none-missing

Originally thought that this can be pushed into 1.4.

But after some thinking, I’ve decided to push this into 2.0 instead, because the changes I made potentially break existing software, and we can’t have that before 2.0.

In the meanwhilst, I can keep tuning this branch.

So, sorry for everyone wanting to see this implemented in the 1.x series: It just won’t happen. You’ll have to import MISSING and use that, instead.

Feel free to explore my strategy of solving this issue in the branch above. Criticism & discussion is of course welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use fixtures — pytest documentation
Once pytest finds them, it runs those fixtures, captures what they returned (if anything), and passes those objects into the test function as...
Read more >
Python Behave hooks not being called - Stack Overflow
I'm just running behave, with no extra arguments. I dont get any errors, but nothing happens on the fixtures files... – julianomontini. Feb...
Read more >
Twisted Mail Tutorial: Building an SMTP Client from Scratch
This tutorial will walk you through the creation of an extremely simple SMTP client application. By the time the tutorial is complete, you...
Read more >
pytest Documentation - Read the Docs
Return None for no custom explanation, otherwise return a list of strings. The strings will be joined by newlines.
Read more >
Python Tutorial - Getting Started with Python and Python Basics
As the input() function returns a string, we need to cast it to int . if __name__ == '__main__': (Line 87): When you...
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