Title: Django backend retains automatically opened client after send failure · Issue #38 · ActiveCampaign/postmark-python · GitHub
Open Graph Title: Django backend retains automatically opened client after send failure · Issue #38 · ActiveCampaign/postmark-python
X Title: Django backend retains automatically opened client after send failure · Issue #38 · ActiveCampaign/postmark-python
Description: Describe the bug EmailBackend.send_messages closes a client it creates only when every batch succeeds. If send_batch raises, or a response contains a per-message failure, the backend retains the open client even when the caller did not e...
Open Graph Description: Describe the bug EmailBackend.send_messages closes a client it creates only when every batch succeeds. If send_batch raises, or a response contains a per-message failure, the backend retains the op...
X Description: Describe the bug EmailBackend.send_messages closes a client it creates only when every batch succeeds. If send_batch raises, or a response contains a per-message failure, the backend retains the op...
Opengraph URL: https://github.com/ActiveCampaign/postmark-python/issues/38
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Django backend retains automatically opened client after send failure","articleBody":"**Describe the bug**\n\n`EmailBackend.send_messages` closes a client it creates only when every batch succeeds. If `send_batch` raises, or a response contains a per-message failure, the backend retains the open client even when the caller did not explicitly open it. This affects both fail_silently settings.\n\n**To reproduce**\n\nWith Django settings configured locally:\n\n```python\nfrom unittest.mock import Mock, patch\nfrom django.core.mail import EmailMessage\nfrom postmark.django import EmailBackend\n\nclient = Mock()\nclient.outbound.send_batch.side_effect = RuntimeError(\"local failure\")\nwith patch(\"postmark.django.backend.SyncServerClient\", return_value=client):\n backend = EmailBackend(server_token=\"local-test\", fail_silently=True)\n backend.send_messages([\n EmailMessage(\"example\", \"body\", \"sender@example.com\", [\"to@example.com\"])\n ])\n assert client.close.called # false\n assert backend.client is None # false\n```\n\n**Expected behavior**\n\nClose automatically created clients on failure as well as success. Preserve an explicitly opened/caller-owned connection for reuse. Keep exception and fail_silently behavior unchanged.\n\n**Environment**\n- postmark-python 0.4.0 / current main\n- Python 3.12, Django 5.2, macOS\n\n**Additional context**\n\nThe send loop and close call can be wrapped in try/finally inside the existing exception-handling boundary. I plan to cover transport errors and API response failures, both ownership modes and both fail_silently settings. Local mocked transport only; no actual emails sent. AI assistance: OpenAI Codex.\n","author":{"url":"https://github.com/Kayvan-Zahiri","@type":"Person","name":"Kayvan-Zahiri"},"datePublished":"2026-10-23T23:57:21Z","url":"https://github.com/ActiveCampaign/postmark-python/issues/38"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:37aaf4ea-dcbc-491d-b94d-6e3625c5df23 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DFF4:2B4B16:351F4A:48A745:6AFE1DF9 |
| html-safe-nonce | 5ad39d74e34b854161f330ff003a18ddaefc4b0eb4e0498129a8d4b6b774ec71 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkY0OjJCNEIxNjozNTFGNEE6NDhBNzQ1OjZBRkUxREY5IiwidmlzaXRvcl9pZCI6IjQwMzE2NDAyNDU4MzIxMzAwNDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2ba02def5e20ff71222fa5c66d1174f27e88d8a681a72fd750f9e80153c28ae4 |
| hovercard-subject-tag | issue:6007232658 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/ActiveCampaign/postmark-python/38/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e6db78dd16742fbc38ff4d4147392935353208b0fe660127d5fadaf06a6dba92/ActiveCampaign/postmark-python/issues/38 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e6db78dd16742fbc38ff4d4147392935353208b0fe660127d5fadaf06a6dba92/ActiveCampaign/postmark-python/issues/38 |
| og:image:alt | Describe the bug EmailBackend.send_messages closes a client it creates only when every batch succeeds. If send_batch raises, or a response contains a per-message failure, the backend retains the op... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Kayvan-Zahiri |
| hostname | github.com |
| expected-hostname | github.com |
| None | d0525ab1464526bf4532a5551aa348cf100dff75ef808a96fc67a08b1d946aa9 |
| turbo-cache-control | no-preview |
| go-import | github.com/ActiveCampaign/postmark-python git https://github.com/ActiveCampaign/postmark-python.git |
| octolytics-dimension-user_id | 563440 |
| octolytics-dimension-user_login | ActiveCampaign |
| octolytics-dimension-repository_id | 1117725016 |
| octolytics-dimension-repository_nwo | ActiveCampaign/postmark-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1117725016 |
| octolytics-dimension-repository_network_root_nwo | ActiveCampaign/postmark-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fef3993a71fa20f7be8e167132fbf9619bc66e12 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width