Fixes db migration with PostgreSQL 17
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
I think we need more @eemeli here to confirm? This seems reasonable to me.
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 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... ^^'
@eemeli ^^
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,
),
]
@flozz Could you share the exact steps to reproduce the problem this PR is trying to fix?
@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! :)