I have a table with 3 rows like this:
| serverID | behavior | limit |
---------------------------------
| 102 | action1 | 5 |
| 103 | action2 | 8 |
I have this function here:
def set_warn_settings(serverID, behavior, limit):
with INSERTION_LOCK:
try:
row = SESSION.query(WarnSettings).filter(WarnSettings.serverID == serverID).first()
if row:
row.behavior = behavior
row.limit = limit
SESSION.add(row)
SESSION.commit()
else:
action = WarnSettings(serverID, behavior, limit)
SESSION.add(action)
SESSION.commit()
finally:
SESSION.close()
When I call the function and one of the arguments is None
, the column's value is replaced with None
instead of leaving it like was before. The function is sometimes called with only one of the arguments having something else than None
.
How can I update a certain column's value while leaving the rest untouched, all from one function?