Skip to content

Commit

Permalink
[FIX] database_cleanup: preserve spaces in quoted identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanRijnhart committed Dec 24, 2023
1 parent b28e4e7 commit ae0fc4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion database_cleanup/identifier_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __conform__(self, protocol):

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:
Expand Down
1 change: 1 addition & 0 deletions database_cleanup/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions database_cleanup/tests/test_identifier_adapter.py
Original file line number Diff line number Diff line change
@@ -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",
)

0 comments on commit ae0fc4f

Please sign in to comment.