public inbox for pgsql-www@postgresql.org  
help / color / mirror / Atom feed
[PATCH] pgarchives: bugfix: increase listsubscription username length
3+ messages / 2 participants
[nested] [flat]

* [PATCH] pgarchives: bugfix: increase listsubscription username length
@ 2025-09-22 19:13  Célestin Matte <celestin.matte@cmatte.me>
  0 siblings, 1 reply; 3+ messages in thread

From: Célestin Matte @ 2025-09-22 19:13 UTC (permalink / raw)
  To: PostgreSQL WWW <pgsql-www@lists.postgresql.org>

The listsubscription username field is populated by pglister_sync,
copying information from auth_user.email, which can be up to
254 characters.
If a user defined an email address that is longer than 30
characters, pglister_sync will crash:

Traceback (most recent call last):
   File "/path/pglister_sync.py", line 83, in <module>
     curs.execute("WITH t(u) AS (SELECT UNNEST(%(usernames)s::text[])), ins(un) AS (INSERT INTO listsubscribers (username, list_id) SELECT u, %(listid)s FROM t WHERE NOT EXISTS (SELECT 1 FROM listsubscribers WHERE username=u AND list_id=%(listid)s) RETURNING username), del(un) AS (DELETE FROM listsubscribers WHERE list_id=%(listid)s AND NOT EXISTS (SELECT 1 FROM t WHERE u=username) RETURNING username) SELECT 'ins',un FROM ins UNION ALL SELECT 'del',un FROM del ORDER BY 1,2", {
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(30)

This patch fixes the issue by using the same max length as any
django email field for this field.
-- 
Célestin Matte


Attachments:

  [text/x-patch] 0001-Increase-listsubscriber-username-field-length.patch (2.0K, 2-0001-Increase-listsubscriber-username-field-length.patch)
  download | inline diff:
From 6b8daacd6c90e0b52384e64e545574162207e5b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <dev@cmatte.me>
Date: Mon, 22 Sep 2025 21:00:50 +0200
Subject: [PATCH] Increase listsubscriber username field length

This field is populated by pglister_sync, copying information from
auth_user.email, which can be up to 254 characters.
---
 .../0005_alter_listsubscriber_username.py      | 18 ++++++++++++++++++
 django/archives/mailarchives/models.py         |  2 +-
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 django/archives/mailarchives/migrations/0005_alter_listsubscriber_username.py

diff --git a/django/archives/mailarchives/migrations/0005_alter_listsubscriber_username.py b/django/archives/mailarchives/migrations/0005_alter_listsubscriber_username.py
new file mode 100644
index 0000000..752cbd6
--- /dev/null
+++ b/django/archives/mailarchives/migrations/0005_alter_listsubscriber_username.py
@@ -0,0 +1,18 @@
+# Generated by Django 5.2.6 on 2025-09-22 18:39
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("mailarchives", "0004_resend_rate_limit"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="listsubscriber",
+            name="username",
+            field=models.CharField(max_length=254),
+        ),
+    ]
diff --git a/django/archives/mailarchives/models.py b/django/archives/mailarchives/models.py
index 44c4469..5362a98 100644
--- a/django/archives/mailarchives/models.py
+++ b/django/archives/mailarchives/models.py
@@ -122,7 +122,7 @@ class ListSubscriber(models.Model):
     # We set the username of the community account instead of a
     # foreign key, because the user might not exist.
     list = models.ForeignKey(List, null=False, blank=False, on_delete=models.CASCADE)
-    username = models.CharField(max_length=30, null=False, blank=False)
+    username = models.CharField(max_length=254, null=False, blank=False)
 
     class Meta:
         unique_together = (('list', 'username'), )
-- 
2.51.0



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [PATCH] pgarchives: bugfix: increase listsubscription username length
@ 2025-09-22 19:28  Célestin Matte <celestin.matte@cmatte.me>
  parent: Célestin Matte <celestin.matte@cmatte.me>
  0 siblings, 1 reply; 3+ messages in thread

From: Célestin Matte @ 2025-09-22 19:28 UTC (permalink / raw)
  To: PostgreSQL WWW <pgsql-www@lists.postgresql.org>

Correction: the field is copied from auth_user.username, which is max 150 characters: https://docs.djangoproject.com/en/5.2/ref/contrib/auth/#django.contrib.auth.models.User.username

Corrected patch attached

On 22/09/2025 21:13, Célestin Matte wrote:
> The listsubscription username field is populated by pglister_sync,
> copying information from auth_user.email, which can be up to
> 254 characters.
> If a user defined an email address that is longer than 30
> characters, pglister_sync will crash:
> 
> Traceback (most recent call last):
>    File "/path/pglister_sync.py", line 83, in <module>
>      curs.execute("WITH t(u) AS (SELECT UNNEST(%(usernames)s::text[])), ins(un) AS (INSERT INTO listsubscribers (username, list_id) SELECT u, %(listid)s FROM t WHERE NOT EXISTS (SELECT 1 FROM listsubscribers WHERE username=u AND list_id=%(listid)s) RETURNING username), del(un) AS (DELETE FROM listsubscribers WHERE list_id=%(listid)s AND NOT EXISTS (SELECT 1 FROM t WHERE u=username) RETURNING username) SELECT 'ins',un FROM ins UNION ALL SELECT 'del',un FROM del ORDER BY 1,2", {
> psycopg2.errors.StringDataRightTruncation: value too long for type character varying(30)
> 
> This patch fixes the issue by using the same max length as any
> django email field for this field.


-- 
Célestin Matte

Attachments:

  [text/x-patch] 0001-Increase-listsubscriber-username-field-length.patch (2.0K, 2-0001-Increase-listsubscriber-username-field-length.patch)
  download | inline diff:
From 6b8daacd6c90e0b52384e64e545574162207e5b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9lestin=20Matte?= <dev@cmatte.me>
Date: Mon, 22 Sep 2025 21:00:50 +0200
Subject: [PATCH] Increase listsubscriber username field length

This field is populated by pglister_sync, copying information from
auth_user.username, which can be up to 150 characters.
---
 .../0005_alter_listsubscriber_username.py      | 18 ++++++++++++++++++
 django/archives/mailarchives/models.py         |  2 +-
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 django/archives/mailarchives/migrations/0005_alter_listsubscriber_username.py

diff --git a/django/archives/mailarchives/migrations/0005_alter_listsubscriber_username.py b/django/archives/mailarchives/migrations/0005_alter_listsubscriber_username.py
new file mode 100644
index 0000000..752cbd6
--- /dev/null
+++ b/django/archives/mailarchives/migrations/0005_alter_listsubscriber_username.py
@@ -0,0 +1,18 @@
+# Generated by Django 5.2.6 on 2025-09-22 18:39
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("mailarchives", "0004_resend_rate_limit"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="listsubscriber",
+            name="username",
+            field=models.CharField(max_length=150),
+        ),
+    ]
diff --git a/django/archives/mailarchives/models.py b/django/archives/mailarchives/models.py
index 44c4469..5362a98 100644
--- a/django/archives/mailarchives/models.py
+++ b/django/archives/mailarchives/models.py
@@ -122,7 +122,7 @@ class ListSubscriber(models.Model):
     # We set the username of the community account instead of a
     # foreign key, because the user might not exist.
     list = models.ForeignKey(List, null=False, blank=False, on_delete=models.CASCADE)
-    username = models.CharField(max_length=30, null=False, blank=False)
+    username = models.CharField(max_length=150, null=False, blank=False)
 
     class Meta:
         unique_together = (('list', 'username'), )
-- 
2.51.0



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [PATCH] pgarchives: bugfix: increase listsubscription username length
@ 2025-12-01 19:56  Magnus Hagander <magnus@hagander.net>
  parent: Célestin Matte <celestin.matte@cmatte.me>
  0 siblings, 0 replies; 3+ messages in thread

From: Magnus Hagander @ 2025-12-01 19:56 UTC (permalink / raw)
  To: Célestin Matte <celestin.matte@cmatte.me>; +Cc: PostgreSQL WWW <pgsql-www@lists.postgresql.org>

Hi!

Better late than never, this has been pushed. Sorry about the delay!

//Magnus

On Mon, 22 Sept 2025 at 21:28, Célestin Matte <celestin.matte@cmatte.me>
wrote:

> Correction: the field is copied from auth_user.username, which is max 150
> characters:
> https://docs.djangoproject.com/en/5.2/ref/contrib/auth/#django.contrib.auth.models.User.username
>
> Corrected patch attached
>
> On 22/09/2025 21:13, Célestin Matte wrote:
> > The listsubscription username field is populated by pglister_sync,
> > copying information from auth_user.email, which can be up to
> > 254 characters.
> > If a user defined an email address that is longer than 30
> > characters, pglister_sync will crash:
> >
> > Traceback (most recent call last):
> >    File "/path/pglister_sync.py", line 83, in <module>
> >      curs.execute("WITH t(u) AS (SELECT UNNEST(%(usernames)s::text[])),
> ins(un) AS (INSERT INTO listsubscribers (username, list_id) SELECT u,
> %(listid)s FROM t WHERE NOT EXISTS (SELECT 1 FROM listsubscribers WHERE
> username=u AND list_id=%(listid)s) RETURNING username), del(un) AS (DELETE
> FROM listsubscribers WHERE list_id=%(listid)s AND NOT EXISTS (SELECT 1 FROM
> t WHERE u=username) RETURNING username) SELECT 'ins',un FROM ins UNION ALL
> SELECT 'del',un FROM del ORDER BY 1,2", {
> > psycopg2.errors.StringDataRightTruncation: value too long for type
> character varying(30)
> >
> > This patch fixes the issue by using the same max length as any
> > django email field for this field.
>
>
> --
> Célestin Matte


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2025-12-01 19:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-09-22 19:13 [PATCH] pgarchives: bugfix: increase listsubscription username length Célestin Matte <celestin.matte@cmatte.me>
2025-09-22 19:28 ` Célestin Matte <celestin.matte@cmatte.me>
2025-12-01 19:56   ` Magnus Hagander <magnus@hagander.net>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox