Fix bug when UPSERTing a column named 'id'
This commit is contained in:
parent
22b64ee480
commit
25477717bc
@ -29,8 +29,14 @@ class Table(object):
|
||||
self.name = normalize_table_name(table_name)
|
||||
self._table = None
|
||||
self._indexes = []
|
||||
self._primary_id = primary_id
|
||||
self._primary_type = primary_type
|
||||
if primary_id is not None:
|
||||
self._primary_id = primary_id
|
||||
else:
|
||||
self._primary_id = self.PRIMARY_DEFAULT
|
||||
if primary_type is not None:
|
||||
self._primary_type = primary_type
|
||||
else:
|
||||
self._primary_type = Types.integer
|
||||
self._auto_create = auto_create
|
||||
|
||||
@property
|
||||
@ -235,8 +241,8 @@ class Table(object):
|
||||
if self._primary_id is not False:
|
||||
# This can go wrong on DBMS like MySQL and SQLite where
|
||||
# tables cannot have no columns.
|
||||
primary_id = self._primary_id or self.PRIMARY_DEFAULT
|
||||
primary_type = self._primary_type or Types.integer
|
||||
primary_id = self._primary_id
|
||||
primary_type = self._primary_type
|
||||
increment = primary_type in [Types.integer, Types.bigint]
|
||||
column = Column(primary_id, primary_type,
|
||||
primary_key=True,
|
||||
|
||||
@ -236,6 +236,12 @@ class TableTestCase(unittest.TestCase):
|
||||
)
|
||||
assert len(self.tbl) == len(TEST_DATA) + 1, len(self.tbl)
|
||||
|
||||
def test_upsert_id(self):
|
||||
table = self.db['banana_with_id']
|
||||
data = dict(id=10, title='I am a banana!')
|
||||
table.upsert(data, ['id'])
|
||||
assert len(table) == 1, len(table)
|
||||
|
||||
def test_update_while_iter(self):
|
||||
for row in self.tbl:
|
||||
row['foo'] = 'bar'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user