Skip to content

Commit

Permalink
restore the contracts of update/extend to the degree that the same co…
Browse files Browse the repository at this point in the history
…lumn identity

isn't appended to the list.  reflection makes use of this.
  • Loading branch information
zzzeek committed Feb 27, 2014
1 parent b642821 commit c2f86c9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/sqlalchemy/sql/base.py
Expand Up @@ -522,17 +522,19 @@ def clear(self):
raise NotImplementedError() raise NotImplementedError()


def remove(self, column): def remove(self, column):
raise NotImplementedError() del self._data[column.key]
self._all_col_set.remove(column)
self._all_columns[:] = [c for c in self._all_columns if c is not column]


def update(self, iter): def update(self, iter):
cols = list(iter) cols = list(iter)
self._all_columns.extend(c for label, c in cols) self._all_columns.extend(c for label, c in cols if c not in self._all_col_set)
self._all_col_set.update(c for label, c in cols) self._all_col_set.update(c for label, c in cols)
self._data.update((label, c) for label, c in cols) self._data.update((label, c) for label, c in cols)


def extend(self, iter): def extend(self, iter):
cols = list(iter) cols = list(iter)
self._all_columns.extend(cols) self._all_columns.extend(c for c in cols if c not in self._all_col_set)
self._all_col_set.update(cols) self._all_col_set.update(cols)
self._data.update((c.key, c) for c in cols) self._data.update((c.key, c) for c in cols)


Expand Down
30 changes: 30 additions & 0 deletions test/base/test_utils.py
Expand Up @@ -454,6 +454,36 @@ def test_dupes_update(self):
# the same as the "_all_columns" collection. # the same as the "_all_columns" collection.
eq_(list(cc), [c1, c2b, c3]) eq_(list(cc), [c1, c2b, c3])


def test_extend_existing(self):
cc = sql.ColumnCollection()

c1, c2, c3, c4, c5 = column('c1'), column('c2'), column('c3'), column('c4'), column('c5')

cc.extend([c1, c2])
eq_(cc._all_columns, [c1, c2])

cc.extend([c3])
eq_(cc._all_columns, [c1, c2, c3])
cc.extend([c4, c2, c5])

eq_(cc._all_columns, [c1, c2, c3, c4, c5])

def test_update_existing(self):
cc = sql.ColumnCollection()

c1, c2, c3, c4, c5 = column('c1'), column('c2'), column('c3'), column('c4'), column('c5')

cc.update([('c1', c1), ('c2', c2)])
eq_(cc._all_columns, [c1, c2])

cc.update([('c3', c3)])
eq_(cc._all_columns, [c1, c2, c3])
cc.update([('c4', c4), ('c2', c2), ('c5', c5)])

eq_(cc._all_columns, [c1, c2, c3, c4, c5])



class LRUTest(fixtures.TestBase): class LRUTest(fixtures.TestBase):


def test_lru(self): def test_lru(self):
Expand Down

0 comments on commit c2f86c9

Please sign in to comment.