Fixed "AttributeError: 'NoneType' object has no attribute 'close'" for SmtpHook#62409
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
SameerMesiah97
left a comment
There was a problem hiding this comment.
Looks fine. But let's wait for CI to run.
guan404ming
left a comment
There was a problem hiding this comment.
Thanks for your contribution.
The core fix (range(0, ...)) seems correct, but all four retry loops in the file need the same treatment. Fixing only get_conn() while leaving aget_conn(), send_email_smtp(), and asend_email_smtp() unfixed is incomplete.
|
@guan404ming, oops, didn't think about them. OK, I'll try to look at them today or tomorrow. Thank you for pointing that out! |
There was a problem hiding this comment.
Pull request overview
This pull request fixes a critical bug where SmtpHook.get_conn() would not establish any SMTP connection when smtp_retry_limit is set to 0, causing an AttributeError: 'NoneType' object has no attribute 'close' when the context manager exits.
Changes:
- Changed retry loop ranges from
range(1, retry_limit + 1)torange(0, retry_limit + 1)to ensure at least one connection attempt - Updated test assertions to reflect the correct number of attempts (retry_limit + 1)
- Added comprehensive test coverage for retry_limit=0 configuration
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| providers/smtp/src/airflow/providers/smtp/hooks/smtp.py | Fixed retry loop logic in 4 locations (get_conn, aget_conn, send_email_smtp, asend_email_smtp) to start at attempt 0 instead of 1 |
| providers/smtp/tests/unit/smtp/hooks/test_smtp.py | Added CONN_ID_0_RETRIES test connection, added test cases for 0-retries configuration, and corrected test assertions to expect retry_limit+1 attempts |
|
@guan404ming, could you please re-review? |
|
@eladkal, why did the 4 checks fail? All of them seem not connected to my changes. |
|
You need to rebase. |
|
@TopCoder2K Converting to draft — this PR doesn't yet meet our Pull Request quality criteria.
See the linked criteria for how to fix each item, then mark the PR "Ready for review". This is not a rejection — just an invitation to bring the PR up to standard. No rush. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
242c77b to
4e7efe9
Compare
|
Damn, Git hooks don't want to work in GitHub Codespaces, so I'm forced to run them locally on my ancient laptop :( |
I think you just need to fix this and we're fine, no need for local run ;-) |
|
@dabla, oh, I didn't know there was highlighting of failed checks in the "Files changed" section, thank you! Let's try. |
4e7efe9 to
7f53fec
Compare
|
@eladkal, could you please start the waiting workflows? |
e426ce8 to
8b458b2
Compare
|
Ok, let's try to break the stalemate with this: |
|
I took a look at [chromium] › tests/e2e/specs/backfill.spec.ts:89:7 › Backfill › Backfill creation and validation › verify backfill with 'All Runs' behavior
[chromium] › tests/e2e/specs/dag-audit-log.spec.ts:78:3 › DAG Audit Log › verify audit log entries display valid datafailed. I'll try to investigate this tomorrow or next week, but any help would be appreciated. |
|
@TopCoder2K — Removing the The label's contract is that the PR is ready for maintainer review — a regression like this means the PR temporarily isn't. Check the failing checks, fix the regression, push, then mark "Ready for review" again to re-enter the queue. See the Pull Request quality criteria. No rush. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
|
It seems that this is again due to the branch obsolescence. Let's try to rebase it. |
46b3e9b to
1be298e
Compare
|
@TopCoder2K — A reviewer (@guan404ming) has requested changes on this PR, so I've removed the Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
|
Oh no, why? @potiuk, the comment above is wrong. I'll be forced to re-enter the queue due to this mistake.( By the way, Guan-Ming has been ignoring this PR for at least 1.5 months. Can anyone else review it? I've stuck in the |
1be298e to
d8a9003
Compare
guan404ming
left a comment
There was a problem hiding this comment.
Thanks for addressing the comments, and sorry for the late re-review. LGTM.
|
Both failed tests seem to be unrelated to my changes. Should I wait until the problems are fixed and then rebase? |
d8a9003 to
915977d
Compare
|
Thank you for rebasing, Ash. Now I see two other errors, and they seem unrelated to my changes. |
|
Does anyone know if accessibility to |
915977d to
dfce44b
Compare
|
Hooray, all tests have been passed! 🥳 |
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
|
Thanks @TopCoder2K! |
This loop inside the
SmtpHook.get_conn()method isn't entered whenself.smtp_retry_limit == 0. It seems enough just to set therange()to start at0(sinceself.smtp_retry_limitis a number of retries = repeated tries after the first try).P.S.
I wasn't able to run the checks due to #62408.
Was generative AI tooling used to co-author this PR?