Skip to content

Commit ae994ac

Browse files
committed
Report the database locale on PostgreSQL 15, and skip what Windows cannot do
Three things, all turned up by CI. get_ctypes.sql only existed from the 16_plus bucket down, so a PostgreSQL 15 server fell back to the default template and reported the server's own lc_collate and lc_ctype settings rather than anything about the database, which is exactly the bug this is meant to fix. datlocprovider and daticulocale both arrived in 15, and 15 is also where a database first stopped necessarily collating according to datcollate and datctype, so the template moves down to the 15_plus bucket unchanged rather than being duplicated. The two libc scenarios deliberately set LC_COLLATE and LC_CTYPE to different values, since that is what proves which of the two columns the query reported. Windows builds accept the CREATE DATABASE but then refuse to open the result, so those two scenarios now skip with the server's own explanation when that is what comes back, and continue to fail on anything else. The builtin scenario no longer skips when template0 uses 'C' or 'POSIX'. That guard belongs to the libc scenarios, which need a template locale distinguishable from the defaults; the builtin scenario distinguishes against the 'C.UTF-8' it creates the database with, and 'C' and 'POSIX' are both perfectly distinguishable from that, so skipping them only lost the scenario on the servers most likely to have a default template0.
1 parent d025f95 commit ae994ac

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/16_plus/get_ctypes.sql renamed to web/pgadmin/browser/server_groups/servers/databases/templates/databases/sql/15_plus/get_ctypes.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{# datlocprovider and daticulocale both arrived in PostgreSQL 15, which is
2+
also where a database first stopped necessarily collating according to
3+
datcollate and datctype, so this bucket starts there. #}
14
SELECT daticulocale AS cname FROM pg_catalog.pg_database
25
WHERE datname = current_database() AND datlocprovider = 'i'
36
UNION

‎web/pgadmin/browser/server_groups/servers/databases/tests/test_db_get_ctypes.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import uuid
2424

25+
import psycopg
2526
from flask import render_template
2627

2728
from pgadmin.utils.route import BaseTestGenerator
@@ -105,7 +106,18 @@ def runTest(self):
105106
else (self.template_collate, 'C')
106107
self._create_database(
107108
"LC_COLLATE '%s' LC_CTYPE '%s'" % (collate, ctype))
108-
self.assertIn(self.template_collate, self._reported_locales())
109+
try:
110+
reported = self._reported_locales()
111+
except psycopg.OperationalError as exc:
112+
# Windows builds accept the CREATE DATABASE but refuse to
113+
# open a database whose collation and character type differ,
114+
# so the pair that proves which of the two columns was read
115+
# cannot be exercised there.
116+
if 'not supported on this platform' not in str(exc):
117+
raise
118+
self.skipTest('This server will not open a database whose '
119+
'collate and ctype differ: %s' % exc)
120+
self.assertIn(self.template_collate, reported)
109121
return
110122

111123
if self.provider == 'builtin':
@@ -121,7 +133,12 @@ def runTest(self):
121133
"the only one a UTF-8 builtin database can "
122134
"use, so a distinguishable one cannot be "
123135
"created here.")
124-
self._skip_unless_distinct_template_locale()
136+
# Unlike the libc scenarios, nothing here needs a template
137+
# locale that differs from the defaults: 'C' and 'POSIX' are
138+
# both perfectly distinguishable from the 'C.UTF-8' the builtin
139+
# database is created with, and skipping them would lose the
140+
# scenario on exactly the servers most likely to have a default
141+
# template0.
125142
self._create_database("LOCALE_PROVIDER builtin "
126143
"BUILTIN_LOCALE 'C.UTF-8' ENCODING UTF8")
127144

0 commit comments

Comments
 (0)