[FIX] database_cleanup: preserve spaces in quoted identifiers

pull/2684/head
Stefan Rijnhart 2023-06-05 18:54:50 +02:00 committed by Miika Nissi
parent 0d2fbc3ec1
commit f80f43c2c0
No known key found for this signature in database
GPG Key ID: B20DC9FCFAF92E7F
3 changed files with 20 additions and 1 deletions

View File

@ -14,7 +14,7 @@ class IdentifierAdapter(ISQLQuote):
def getquoted(self):
def is_identifier_char(c):
return c.isalnum() or c in ["_", "$"]
return c.isalnum() or c in (["_", "$", " "] if self.quote else ["_", "$"])
format_string = '"%s"'
if not self.quote:

View File

@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import common
from . import test_create_indexes
from . import test_identifier_adapter
from . import test_purge_columns
from . import test_purge_data
from . import test_purge_menus

View File

@ -0,0 +1,18 @@
from odoo.tests import TransactionCase
from odoo.addons.database_cleanup.identifier_adapter import IdentifierAdapter
class TestIdentifierAdapter(TransactionCase):
def test_column_name_with_spaces(self):
"""Spaces in column names are preserved except in unquoted identifiers."""
self.assertEqual(
self.env.cr.mogrify("%s", (IdentifierAdapter("snailmail_cover "),)),
b'"snailmail_cover "',
)
self.assertEqual(
self.env.cr.mogrify(
"%s", (IdentifierAdapter("snailmail_cover ", quote=False),)
),
b"snailmail_cover",
)