Repository navigation
fix(smtp): honor the local hostname during STARTTLS - #45909
Conversation
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-10 01:46:14.003359623 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-10 01:46:01.295167744 +0000
@@ -2699,7 +2699,7 @@
ERROR Object of class `FromClause` has no attribute `drop` [missing-attribute]
--> tests/unit_tests/controllers/trigger/test_trigger.py:46:5
ERROR `_RequestStub` is not assignable to attribute `request` with type `Request` [bad-assignment]
- --> tests/unit_tests/controllers/trigger/test_webhook.py:70:22
+ --> tests/unit_tests/controllers/trigger/test_webhook.py:47:22
ERROR Argument `None` is not assignable to parameter `type` with type `EndUserType | SQLCoreOperations[EndUserType]` in function `models.model.EndUser.__init__` [bad-argument-type]
--> tests/unit_tests/controllers/web/test_wraps.py:387:81
ERROR Expected 1 more positional argument [bad-argument-count]
@@ -4121,7 +4121,7 @@
ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
--> tests/unit_tests/core/rag/extractor/test_excel_extractor.py:17:56
ERROR Argument `object | None` is not assignable to parameter `session` with type `Session | None` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
- --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:251:85
+ --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:222:85
ERROR Object of class `NoneType` has no attribute `strip` [missing-attribute]
--> tests/unit_tests/core/rag/extractor/test_markdown_extractor.py:30:16
ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
@@ -5895,42 +5895,50 @@
--> tests/unit_tests/services/tools/test_tools_transform_service.py:85:9
ERROR Object of class `Mapping` has no attribute `startswith` [missing-attribute]
--> tests/unit_tests/services/tools/test_tools_transform_service.py:819:20
+ERROR Argument `dict[str, Any]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.schedule_service.ScheduleService.to_schedule_config` [bad-argument-type]
+ --> tests/unit_tests/services/trigger/test_schedule_service.py:549:61
+ERROR Argument `dict[str, str | dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.schedule_service.ScheduleService.to_schedule_config` [bad-argument-type]
+ --> tests/unit_tests/services/trigger/test_schedule_service.py:563:56
+ERROR Argument `dict[str, str | dict[str, str | dict[str, str]]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.schedule_service.ScheduleService.to_schedule_config` [bad-argument-type]
+ --> tests/unit_tests/services/trigger/test_schedule_service.py:580:61
+ERROR Argument `dict[str, str | dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.schedule_service.ScheduleService.to_schedule_config` [bad-argument-type]
+ --> tests/unit_tests/services/trigger/test_schedule_service.py:592:56
ERROR Argument `dict[str, dict[Unknown, Unknown]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:589:83
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:507:83
ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:599:83
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:517:83
ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:609:83
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:527:83
ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:618:83
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:536:83
ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:627:83
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:545:83
ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:637:83
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:555:83
ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:895:38
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:807:92
ERROR Argument `dict[str, dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:924:42
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:834:87
ERROR Argument `dict[str, dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:946:42
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:854:87
ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:966:45
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:872:90
ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:987:41
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:891:95
ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:1011:45
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:913:90
ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:1032:45
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:932:90
ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:1053:45
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:951:90
ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:1073:41
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:969:95
ERROR Argument `dict[str, str | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService._validate_http_metadata` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:1356:61
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:1249:61
ERROR Argument `dict[str, dict[str, int] | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:1368:59
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:1261:59
ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
- --> tests/unit_tests/services/trigger/test_webhook_service.py:1379:69
+ --> tests/unit_tests/services/trigger/test_webhook_service.py:1272:69
ERROR Cannot find module `dify_graph.enums` [missing-import]
--> tests/unit_tests/services/workflow/test_workflow_converter.py:36:5
ERROR Cannot find module `dify_graph.model_runtime.entities.llm_entities` [missing-import]
|
Pyrefly Type Coverage
|
|
Please fix the broken CI |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #45909 +/- ##
==========================================
- Coverage 90.09% 90.09% -0.01%
==========================================
Files 6267 6269 +2
Lines 391981 392018 +37
Branches 78446 78450 +4
==========================================
+ Hits 353152 353184 +32
- Misses 32731 32741 +10
+ Partials 6098 6093 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Head branch was pushed to by a user without write access
|
@crazywoola Thanks for reviewing! Fixed the Python Style failure in ac7e5d1 by adding the missing type annotations to the new SMTP tests and relay helper. Production code and test assertions are unchanged in this follow-up. Rechecked locally using the unit-test Pyrefly strict configuration: 0 diagnostics. The focused SMTP/SendGrid suite passes all 44 cases, and Ruff lint/format checks pass. GitHub automatically dismissed the earlier approval when this commit was pushed. The updated workflows are currently awaiting maintainer approval to run; could you please approve the runs and take another look when convenient? |
SMTP_LOCAL_HOSTNAME set to an empty string would reach smtplib as local_hostname="" and produce a bare ehlo with no hostname argument. Normalize blank values to None so smtplib falls back to its socket.getfqdn() default, and cover the empty value in the identity tests.
Fixes #45908
Summary
STARTTLS mail can be rejected by identity-checking relays even when the operator
sets SMTP_LOCAL_HOSTNAME: the two explicit EHLO calls send the remote server's
address instead of the configured client identity.
Use
smtp.ehlo()before and after STARTTLS so smtplib uses the local hostnamealready supplied at construction, including its default when no override is
set. Preserve TLS negotiation, authentication, message content and cleanup.
The behavior change is two calls; the method docstring documents the outcome
contract. No public settings or dependencies change.
Related #30957 / #30975 introduced the hostname override, but left these two
STARTTLS calls overriding it.
Verification
The new cases use real DifyConfig, SMTPClient, Python smtplib, loopback TCP,
ephemeral TLS certificates, STARTTLS/implicit SSL and MIME/envelope exchanges.
They do not mock the SMTP client or replace its settings module.
Certificate generation uses cryptography, an existing backend dependency;
tests require no external SMTP service or system openssl executable.
Before the fix, the two STARTTLS identity cases fail with SMTPSenderRefused
550; the four plain/SSL controls pass. After the fix, all six pass.
There are 19 new real-protocol cases, 21 existing SMTP cases and four unchanged
SendGrid cases: 44 passed. Existing SendGrid cases mock their external SDK;
no live SendGrid validation is claimed.
From the repository root, using Python 3.13.18 and a small environment with
the matching lockfile versions of pytest, Ruff, Pyrefly, Pydantic/settings,
cryptography, httpx and SendGrid:
Focused tests: 44 passed. Ruff lint/format: passed. Targeted Pyrefly:
0 diagnostics, with its visible PYTHONPATH environment warning.
--noconftestavoids the application's shared database/Redis fixture setup;both selected library modules are self-contained and still load real settings.
Coverage options were disabled for this focused run. No new skips, weakened
assertions or production exception suppression were introduced.
The complete backend environment, application mail-task suite, full suite,
Docker integration and real external mail providers were not exercised.
These results are Windows/Python 3.13 source-level and local protocol proof,
not an end-to-end deployed Dify or cross-platform claim. The initial upstream CI passed API unit tests (both shards), controller tests
and integration tests. Python Style exposed missing annotations in the new
tests under the separate strict unit-test configuration. The follow-up adds
those annotations; local strict checking now reports 0 diagnostics and the
same focused suite passes all 44 cases. Updated-head CI is pending.
Screenshots
No visual change. Wire-level before/after:
Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint godsNo separate user documentation is needed for honoring an existing setting; its
definition already describes the intended behavior. The method docstring was
updated. The last checklist item is intentionally unchecked: the exact focused
checks above ran, not full make targets or frontend checks.
AI assistance covered investigation, implementation, real-protocol regression
tests, focused checks and drafting.
From Codex