#37345 closed New feature (needsnewfeatureprocess)
Add mailer shorthand for mailers[DEFAULT_MAILER_ALIAS]
| Reported by: | Johannes Maron | Owned by: | ssknight-23 |
|---|---|---|---|
| Component: | Core (Mail) | Version: | 6.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Johannes Maron, ssknight-23, Mike Edmunds | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
Howdy,
The new mailers interfaces is lacking a django.db.connection equivalent.
A django.mail.mailer shorthand for mailers[DEFAULT_MAILER_ALIAS] would simplify the transition away from get_connection.
I would have complained earlier during development, but I simply missed it. Only that I am migrating a project now, I realize it's inconsistent with django.db or django.cache.
Cheerio
-Joe
Change History (8)
comment:1 by , 3 weeks ago
comment:2 by , 3 weeks ago
| Cc: | added |
|---|---|
| Owner: | set to |
| Status: | new → assigned |
comment:3 by , 3 weeks ago
| Cc: | added |
|---|
comment:4 by , 3 weeks ago
| Resolution: | → invalid |
|---|---|
| Status: | assigned → closed |
As pointed out in comment:1, django.core.mail.mailers.default returns the default mailer instance (docs). It is meant to parallel django.db.connection, django.core.cache.cache, django.tasks.default_task_backend, and similar accessors.
We can't easily create a module-level accessor like django.core.mail.default_mailer using ConnectionProxy or LazyObject (like the similar accessors do) because those require cacheable instances. In general, EmailBackend instances are not cacheable.
follow-up: 6 comment:5 by , 3 weeks ago
| Resolution: | invalid |
|---|---|
| Status: | closed → new |
Is it worth making the same path available on other connection proxies?
For example: django.db.connections.default, django.cache.caches.default, ...
The purpose of this DEP was consistency, right? My confusion may be an indicator that there's still some work to be done. And I pride myself on knowing Django somewhat well. Newcomers might have an even harder time understanding this.
comment:6 by , 3 weeks ago
Replying to Johannes Maron:
Is it worth making the same path available on other connection proxies?
For example:django.db.connections.default,django.cache.caches.default, ...
I like that idea. (And then maybe eventually deprecating the module-level lazy proxies.)
It might be better to open a separate ticket specifically for that request, to avoid confusion.
comment:7 by , 3 weeks ago
| Resolution: | → needsnewfeatureprocess |
|---|---|
| Status: | new → closed |
| Type: | Cleanup/optimization → New feature |
I'll pass it down the proper channels then :)
Can you add more information?
I think we already support this for default(as you mentioned for default) alias:
So we can use
.defaultwith mailers. But all other aliases (including default) can be accessed usingmail.mailers["alias"].Check this out: https://docs.djangoproject.com/en/dev/topics/email/