Skip to content

Commit 599aa0e

Browse files
committed
[FIX] ColumnList.using()
It now keep the value of `self` for not specified arguments. Part-of: #238 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent b0fd70a commit 599aa0e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/base/tests/test_util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,10 @@ def test_ColumnList(self):
864864

865865
self.assertIs(columns.using(), columns)
866866

867+
ulc = columns.using(leading_comma=True)
868+
self.assertTrue(s(ulc.using(alias="x")), ', "x"."a", "x"."A"')
869+
self.assertIs(ulc, ulc.using(leading_comma=True))
870+
867871

868872
class TestORM(UnitTestCase):
869873
def test_create_cron(self):

src/util/pg.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,10 @@ def get_depending_views(cr, table, column):
960960
return cr.fetchall()
961961

962962

963+
# sentinel object for function parameters to not alter.
964+
KEEP_CURRENT = object()
965+
966+
963967
class ColumnList(UserList, sql.Composable):
964968
"""
965969
Encapsulate a list of elements that represent column names.
@@ -1025,7 +1029,7 @@ def from_unquoted(cls, cr, list_):
10251029
quoted = [quote_ident(c, cr._cnx) for c in list_]
10261030
return cls(list_, quoted)
10271031

1028-
def using(self, leading_comma=False, trailing_comma=False, alias=None):
1032+
def using(self, leading_comma=KEEP_CURRENT, trailing_comma=KEEP_CURRENT, alias=KEEP_CURRENT):
10291033
"""
10301034
Set up parameters to render this list as a string.
10311035
@@ -1036,12 +1040,16 @@ def using(self, leading_comma=False, trailing_comma=False, alias=None):
10361040
:return: a copy of the list with the parameters set
10371041
:rtype: :class:`~odoo.upgrade.util.pg.ColumnList`
10381042
"""
1039-
if self._leading_comma is leading_comma and self._trailing_comma is trailing_comma and self._alias == alias:
1043+
if (
1044+
(leading_comma is KEEP_CURRENT or self._leading_comma is leading_comma)
1045+
and (trailing_comma is KEEP_CURRENT or self._trailing_comma is trailing_comma)
1046+
and (alias is KEEP_CURRENT or self._alias == alias)
1047+
):
10401048
return self
10411049
new = ColumnList(self._unquoted_columns, self.data)
1042-
new._leading_comma = leading_comma
1043-
new._trailing_comma = trailing_comma
1044-
new._alias = alias
1050+
new._leading_comma = self._leading_comma if leading_comma is KEEP_CURRENT else bool(leading_comma)
1051+
new._trailing_comma = self._trailing_comma if trailing_comma is KEEP_CURRENT else bool(trailing_comma)
1052+
new._alias = self._alias if alias is KEEP_CURRENT else str(alias) if alias is not None else None
10451053
return new
10461054

10471055
def as_string(self, context):

0 commit comments

Comments
 (0)