anymail / django-anymail

Django email backends and webhooks for Amazon SES, Brevo (Sendinblue), MailerSend, Mailgun, Mailjet, Postmark, Postal, Resend, SendGrid, SparkPost, Unisender Go and more
https://anymail.dev
BSD 3-Clause "New" or "Revised" License
1.65k stars 125 forks source link

Merging/Combine ESP Options get lost/overwritten #338

Closed mounirmesselmeni closed 10 months ago

mounirmesselmeni commented 11 months ago

Reporting an error? It's helpful to know:

The documentation says that when using ESP extra those options will be merged if defined in message.esp_extra, but in reality those options get overriden, if I pass in message.esp_extra for example the pool_name, the default transactional will be missing.

This is because inside anymail's combine function, the python dict.update check only for first level.

In other words:

dict1 = {"options": {"transactional": True}}
dict2 = {"options": {"pool_name": "custom_poolname"}}

dict1.update(dict2)
# will be -> {"options": {"pool_name": "custom_poolname"}}

this is what is done in the combine function https://github.com/anymail/django-anymail/blob/main/anymail/utils.py#L50

medmunds commented 11 months ago

@mounirmesselmeni thanks for the bug report. We should use a deep merge for esp_extra. (This will only affect ESPs that use nested data structures in their payloads: Sparkpost, Mandrill, maybe a few others I'm forgetting.)

medmunds commented 10 months ago

Fix released in Anymail 10.2