{"record":{"id":"bf431ac57323dd75","repo":"django/django","slug":"fail-silently-cannot-be-used-with-a-connection-pa-bf431a","errorCode":null,"errorMessage":"fail_silently cannot be used with a connection. Pass fail_silently to get_connection() instead.","messagePattern":"fail_silently cannot be used with a connection\\. Pass fail_silently to get_connection\\(\\) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"django/core/mail/message.py","lineNumber":410,"sourceCode":"        #   return mailer.send_messages([self])\n\n        from django.core import mail\n\n        if fail_silently:\n            warn_about_external_use(FAIL_SILENTLY_ARG_WARNING, RemovedInDjango70Warning)\n        if hasattr(self, \"get_connection\"):\n            raise AttributeError(\n                \"EmailMessage no longer supports the undocumented \"\n                \"get_connection() method.\"\n            )\n\n        if using is not None:\n            report_using_incompatibility(self._connection, fail_silently)\n            connection = mail.mailers[using]\n        elif self._connection:\n            connection = self._connection\n            if fail_silently:\n                raise TypeError(\n                    \"fail_silently cannot be used with a connection. \"\n                    \"Pass fail_silently to get_connection() instead.\"\n                )\n        else:\n            connection = mail.get_connection(fail_silently=fail_silently)\n\n        return connection.send_messages([self])\n\n    def attach(self, filename=None, content=None, mimetype=None):\n        \"\"\"\n        Attach a file with the given filename and content. The filename can\n        be omitted and the mimetype is guessed, if not provided.\n\n        If the first parameter is a MIMEBase subclass, insert it directly\n        into the resulting message attachments.\n\n        For a text/* mimetype (guessed or specified), when a bytes object is\n        specified as content, decode it as UTF-8. If that fails, set the","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/core/mail/message.py#L392-L428","documentation":"EmailMessage.send() (django/core/mail/message.py:410) raises TypeError if you pass fail_silently=True while the message already carries an explicit connection (self._connection). fail_silently is a property of the connection, not the message, so combining the two is contradictory and ambiguous.","triggerScenarios":"msg = EmailMessage(connection=conn); msg.send(fail_silently=True) — using is None, self._connection is set, and fail_silently is true, reaching the raise at line 410.","commonSituations":"Pre-creating a connection with custom backend settings then trying to make sending fault-tolerant via the message; upgrading code that mixed the two semantics.","solutions":["Pass fail_silently when opening the connection: get_connection(fail_silently=True).","Drop fail_silently from send() and let the existing connection control error behavior.","Migrate to the new mailers API (using= alias) where fail_silently is configured on the mailer."],"exampleFix":"// before\nconn = get_connection()\nmsg = EmailMessage(connection=conn)\nmsg.send(fail_silently=True)\n// after\nconn = get_connection(fail_silently=True)\nmsg = EmailMessage(connection=conn)\nmsg.send()","handlingStrategy":"validation","validationCode":"def send_safely(msg, fail_silently=False):\n    if fail_silently and getattr(msg, \"_connection\", None) is not None:\n        raise TypeError(\n            \"fail_silently cannot be combined with an explicit connection; \"\n            \"open the connection with fail_silently instead.\"\n        )\n    return msg.send(fail_silently=fail_silently)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide error semantics at connection-open time, not at send time.","Never combine an explicit connection with fail_silently on send().","Migrate to the mailers API where fail_silently lives on the mailer configuration."],"tags":["email","connection","configuration"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}