pontoon icon indicating copy to clipboard operation
pontoon copied to clipboard

Fixes db migration with PostgreSQL 17

Open flozz opened this issue 1 month ago • 5 comments

An error occurs when running the database migration 81 on PostgreSQL 17 (I have not tested on PostgreSQL 16, and it works with PostgreSQL 15):

django.db.utils.DataError: invalid regular expression: invalid escape \ sequence

This PR just replaces a \S escape sequence by [^[:space:]] that is equivalent¹ but that works fine on PG17. :)

¹ Doc: https://www.postgresql.org/docs/current/functions-matching.html#:~:text=matches%20any%20non-whitespace%20character

flozz avatar Nov 12 '25 08:11 flozz

I think we need more @eemeli here to confirm? This seems reasonable to me.

flodolo avatar Nov 12 '25 17:11 flodolo

This is rather surprising, as according to the docs linked to above, \S should work also in Postgres 17. I'm going to see if I can replicate this issue, and get a better handle for what's going on here.

eemeli avatar Nov 13 '25 06:11 eemeli

@eemeli what's strange is that the \S only cause a problem in this precise context and not in regexp_replace()... It is not very consistent... ^^'

flozz avatar Nov 13 '25 08:11 flozz

@eemeli ^^

mathjazz avatar Dec 02 '25 13:12 mathjazz

I'm unable to replicate this problem with PostgreSQL 17.7 running on MacOS using Postgres.app. To test this, I ran this dummy migration on a test_pontoon database on pg17 with no problems:

from django.db import migrations

class Migration(migrations.Migration):
    dependencies = [("base", "0100_android_as_mf2")]

    operations = [
        migrations.RunSQL(
            r"""
            UPDATE base_entity e
            SET string = '' || e.string
            WHERE e.string SIMILAR TO '%[^\S\n]%'
            """,
            reverse_sql=migrations.RunSQL.noop,
        ),
    ]

eemeli avatar Dec 08 '25 16:12 eemeli

@flozz Could you share the exact steps to reproduce the problem this PR is trying to fix?

mathjazz avatar Dec 18 '25 11:12 mathjazz

@mathjazz yep, i wanted to do it this week but i will probably not have the time. I'll try to do it next week! :)

flozz avatar Dec 18 '25 14:12 flozz