Skip to content

Conversation

@flozz
Copy link
Collaborator

@flozz flozz commented Nov 12, 2025

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

@mathjazz mathjazz requested a review from flodolo November 12, 2025 17:29
@flodolo
Copy link
Collaborator

flodolo commented Nov 12, 2025

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

@mathjazz mathjazz requested a review from eemeli November 12, 2025 18:03
@eemeli
Copy link
Member

eemeli commented Nov 13, 2025

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 eemeli self-assigned this Nov 13, 2025
@flozz
Copy link
Collaborator Author

flozz commented Nov 13, 2025

@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... ^^'

@mathjazz
Copy link
Collaborator

mathjazz commented Dec 2, 2025

@eemeli ^^

@eemeli
Copy link
Member

eemeli commented Dec 8, 2025

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,
        ),
    ]

@mathjazz
Copy link
Collaborator

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

@flozz
Copy link
Collaborator Author

flozz commented Dec 18, 2025

@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
Copy link
Collaborator Author

flozz commented Dec 22, 2025

Ok... It seems we have multiple PG versions installed on our server... The IaC installs pg17 (via Ansible)... BUT the used psql client tool is v18.x and the running server is... v13.x... I think we can close this PR. It probably works with pg17, i will cleanup the server and check everyting is ok later... ¬_¬'

Sorry for the time you lost on this :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants