Skip to content

Commit

Permalink
Fix upsert with limited number of columns (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Jan 30, 2022
1 parent 307ec95 commit 312c08a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ def upsert(self, table, row=None, **kw):
keyname.add('oid')
for n in attnames:
if n not in keyname:
value = kw.get(n, True)
value = kw.get(n, n in row)
if value:
if not isinstance(value, basestring):
value = 'excluded.%s' % col(n)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_classic_dbwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,12 @@ def testUpsert(self):
s = dict(m=3, u='z')
r = upsert(table, s, oid='invalid')
self.assertIs(r, s)
s = dict(n=2)
# do not modify columns missing in the dict
r = upsert(table, s)
self.assertIs(r, s)
r = query(q).getresult()
self.assertEqual(r, [(1, 'x2'), (2, 'y3')])

def testUpsertWithOids(self):
if not self.oids:
Expand Down

0 comments on commit 312c08a

Please sign in to comment.