Monday, March 27, 2023

Re: Setting recipient name in EmailMultiAlternatives

I haven't read the documents myself that I am referring to here. But they should come as a help to you with your question.

Try to follow the generalized rules when having some public namespace ( or address).

Regards,
--
Sharif
On Monday, March 27, 2023 at 07:12:51 PM GMT+6, Peter Benjamin Ani <benjaminparish6@gmail.com> wrote:


I don't fully understand the error, can you describe it more please 

On Mon, 27 Mar 2023, 13:54 Sylvain, <sylvain.fankhauser@gmail.com> wrote:
Hello,

I'm using the following code to send mails to my users, with their name appearing in the `To` header:

msg = EmailMultiAlternatives(subject=subject, body=body, to=f"{user.get_full_name()} <{user.email}>")
msg.send()

It works fine but if you have a special character in your name (such as a comma) then `msg.send()` will fail because `sanitize_address` raises an exception. Note that this will only fail with the SMTP backend because all other backends (such as the console backend) don't sanitize the address, so even if you try to write tests for this case, it won't fail unless you actually use the SMTP backend.

I couldn't find any indication in the Django docs on how to correctly include the name of the recipient in an e-mail so I started digging in the code. I found that the `sanitize_address` function (which uses the email.headerregistry.parser module of Python's, which doesn't seem to be documented) accepts either a string or a tuple of (name, address), so I thought I could use `to=(user.get_full_name(), user.email)` which seemed quite elegant, but doesn't really work because the value is not sanitized before it's put in the `To` header so it will show up like `(Jane Doe, jane@example.com)` in the recipient mailbox.

However, it seems calling `sanitize_address` directly works, like so:

msg = EmailMultiAlternatives(subject=subject, body=body, to=sanitize_address((user.get_full_name(), user.email), settings.DEFAULT_CHARSET))

But since there's no mention of `sanitize_address` in the Django docs, I'm not sure it's the right way to do it. And since I couldn't find anything on this topic on the internet I think I might be missing something obvious. Could anyone point me in the right direction?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9f64152c-a5b3-4995-a539-1359416e9decn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPxt_2XOf4b3ZPP-Sa8GPvf9iaVZNhyjwjyF-5DtysGqAQxm4A%40mail.gmail.com.

Re: Setting recipient name in EmailMultiAlternatives

I don't fully understand the error, can you describe it more please 

On Mon, 27 Mar 2023, 13:54 Sylvain, <sylvain.fankhauser@gmail.com> wrote:
Hello,

I'm using the following code to send mails to my users, with their name appearing in the `To` header:

msg = EmailMultiAlternatives(subject=subject, body=body, to=f"{user.get_full_name()} <{user.email}>")
msg.send()

It works fine but if you have a special character in your name (such as a comma) then `msg.send()` will fail because `sanitize_address` raises an exception. Note that this will only fail with the SMTP backend because all other backends (such as the console backend) don't sanitize the address, so even if you try to write tests for this case, it won't fail unless you actually use the SMTP backend.

I couldn't find any indication in the Django docs on how to correctly include the name of the recipient in an e-mail so I started digging in the code. I found that the `sanitize_address` function (which uses the email.headerregistry.parser module of Python's, which doesn't seem to be documented) accepts either a string or a tuple of (name, address), so I thought I could use `to=(user.get_full_name(), user.email)` which seemed quite elegant, but doesn't really work because the value is not sanitized before it's put in the `To` header so it will show up like `(Jane Doe, jane@example.com)` in the recipient mailbox.

However, it seems calling `sanitize_address` directly works, like so:

msg = EmailMultiAlternatives(subject=subject, body=body, to=sanitize_address((user.get_full_name(), user.email), settings.DEFAULT_CHARSET))

But since there's no mention of `sanitize_address` in the Django docs, I'm not sure it's the right way to do it. And since I couldn't find anything on this topic on the internet I think I might be missing something obvious. Could anyone point me in the right direction?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9f64152c-a5b3-4995-a539-1359416e9decn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPxt_2XOf4b3ZPP-Sa8GPvf9iaVZNhyjwjyF-5DtysGqAQxm4A%40mail.gmail.com.

Setting recipient name in EmailMultiAlternatives

Hello,

I'm using the following code to send mails to my users, with their name appearing in the `To` header:

msg = EmailMultiAlternatives(subject=subject, body=body, to=f"{user.get_full_name()} <{user.email}>")
msg.send()

It works fine but if you have a special character in your name (such as a comma) then `msg.send()` will fail because `sanitize_address` raises an exception. Note that this will only fail with the SMTP backend because all other backends (such as the console backend) don't sanitize the address, so even if you try to write tests for this case, it won't fail unless you actually use the SMTP backend.

I couldn't find any indication in the Django docs on how to correctly include the name of the recipient in an e-mail so I started digging in the code. I found that the `sanitize_address` function (which uses the email.headerregistry.parser module of Python's, which doesn't seem to be documented) accepts either a string or a tuple of (name, address), so I thought I could use `to=(user.get_full_name(), user.email)` which seemed quite elegant, but doesn't really work because the value is not sanitized before it's put in the `To` header so it will show up like `(Jane Doe, jane@example.com)` in the recipient mailbox.

However, it seems calling `sanitize_address` directly works, like so:

msg = EmailMultiAlternatives(subject=subject, body=body, to=sanitize_address((user.get_full_name(), user.email), settings.DEFAULT_CHARSET))

But since there's no mention of `sanitize_address` in the Django docs, I'm not sure it's the right way to do it. And since I couldn't find anything on this topic on the internet I think I might be missing something obvious. Could anyone point me in the right direction?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9f64152c-a5b3-4995-a539-1359416e9decn%40googlegroups.com.

Sunday, March 26, 2023

Re: No downtime rolling upgrades with migration

Depending on the requirements. Either two different databases or point to one database.

Or
Link one database to master (read and write)

Another database instance to read only.

And you can change Another database to main.

Cheers 


On Sun, 26 Mar 2023, 22:33 Sandip Bhattacharya, <sandipb@showmethesource.org> wrote:


On Mar 26, 2023, at 4:32 PM, Damanjeet Singh <mailtodaman@gmail.com> wrote:
3. How do you do non-backward compatible schema upgrades? Do you do it out of band from deployments? Do you shift traffic to a different cluster, and then zero traffic upgrade the whole cluster at once?

Daman: Blue Green deployment can help. You can distribute traffic to old and new. When all stable then move everything. You can use kubernetes with helm.


Do you do blue-green deployments with two different databases? 

- Sandip


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/66989169-7601-4CA1-A54B-B9B29F7B719B%40showmethesource.org.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGLHGi7iorAPEvhb5UteJT9Hoy7wwaMfT5D8AtWNKh5pH2uj-A%40mail.gmail.com.

Re: No downtime rolling upgrades with migration

Hello,

Please read my reply below.

Best of luck.

Regards

On Sun, 26 Mar 2023, 21:17 Sandip Bhattacharya, <sandipb@showmethesource.org> wrote:
New to django, so wanted to ask some questions that I didn't find good resources for:

1. If you deploy django apps using docker, do you run migrations before launching gunicorn/uwsgi etc within the docker image?
Daman:This is all upto you. Better to do when creating container. As you can also upgrade from git. 

2. If you do, how does rolling migrations work? Won't the non-upgraded replicas start erroring if the new schema is not backward compatible?
Daman:Create blue green deployment.

3. How do you do non-backward compatible schema upgrades? Do you do it out of band from deployments? Do you shift traffic to a different cluster, and then zero traffic upgrade the whole cluster at once?

Daman: Blue Green deployment can help. You can distribute traffic to old and new. When all stable then move everything. You can use kubernetes with helm.


Thanks,
  Sandip

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/A9719D24-F6DA-45A6-A30A-EA8EA34754A1%40showmethesource.org.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGLHGi5p9MgPyhKs-x%3D_84CGhjcQNy70mQGJK-v8rBi5m3znTA%40mail.gmail.com.

Re: It is impossible to add a non-nullable field 'details1' to feature without specifying a default. This is because the database needs something to populate existing rows.

So what would you want for existing entries in the table which were added before you changed the model?

If you are ok with them being empty, you should use:
details = models.CharField(max_length=500, default="")

And run migrate again.

If you are ok instead of this column being null, then:
details = models.CharField(max_length=500, null=True, blank=True)

I don't have a huge experience with migrations, so others can correct me if I am wrong, but intuitively I feel that defaults should be captured in code than doing one-off fixes manually while running migrations at the command line.

Thanks,
  Sandip


On Mar 25, 2023, at 12:08 AM, Ebenezer Otchere <swazyman1994@gmail.com> wrote:

Am new in django and have been getting errors in migrations, i need help
when i try to do migrations it keeps telling me this
it is impossible to add a non-nullable field 'details' to feature without specifying a default. This is because the database needs something to populate existing rows.
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit and manually define a default value in models.py.
Thank you  in advance
from django.db import models

# Create your models here.


class feature(models.Model) :
   
    name = models.CharField(max_length=100)
    extra = models.CharField(max_length=100)
    details1 = models.CharField(max_length=500)
   
class art(models.Model):
   
    name = models.CharField(max_length=100)
    details = models.CharField(max_length=500)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/06f462e2-3e1d-4a1a-8a97-b183586e5663n%40googlegroups.com.

Re: nexmo

Can we use english please 

On Sun, Mar 26, 2023, 10:43 PM Morgan <dallymorganndongella97@gmail.com> wrote:
bonsoir jaimerai utilisé l'api nexmo pour envoyer des msg, quelqu'un l'a t-il deja fait ici??

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4131eeb8-69c5-45eb-9907-5b9b448f8ee0n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABEjOA8kT%2BVkt3hcbHe-NOX-BBwc3D5K51Rx3EZvnQSY7ukxiA%40mail.gmail.com.