public inbox for pgsql-www@postgresql.org  
help / color / mirror / Atom feed
From: Célestin Matte <celestin.matte@cmatte.me>
To: PostgreSQL WWW <pgsql-www@lists.postgresql.org>
Subject: [PATCH] pgarchives: bugfix: increase listsubscription username length
Date: Mon, 22 Sep 2025 21:13:02 +0200
Message-ID: <281f9ff6-62fd-45fa-9396-0dbf1b4abae0@cmatte.me> (raw)

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



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-www@postgresql.org
  Cc: celestin.matte@cmatte.me, pgsql-www@lists.postgresql.org
  Subject: Re: [PATCH] pgarchives: bugfix: increase listsubscription username length
  In-Reply-To: <281f9ff6-62fd-45fa-9396-0dbf1b4abae0@cmatte.me>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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