gabcares commited on
Commit
d1b3409
·
verified ·
1 Parent(s): 88268b9

Update main.py

Browse files

Handle delete and update separately

Files changed (1) hide show
  1. main.py +8 -3
main.py CHANGED
@@ -185,11 +185,16 @@ async def sms_posts(instance: ResultItem, idx: str = None, action: str = "add")
185
 
186
  try:
187
  if checker:
188
- if action == "delete":
 
 
 
 
189
  await session.delete(existing) # Asynchronous
190
  await session.commit()
191
- else: # add or update use add
192
- session.add(instance) # Not asynchronous
 
193
  await session.commit()
194
  await session.refresh(instance)
195
  result = instance
 
185
 
186
  try:
187
  if checker:
188
+ if action == "add":
189
+ session.add(instance) # Not asynchronous
190
+ await session.commit()
191
+ result = instance
192
+ elif action == "delete":
193
  await session.delete(existing) # Asynchronous
194
  await session.commit()
195
+ else: # update
196
+ existing.update(instance)
197
+ session.add(existing) # Not asynchronous
198
  await session.commit()
199
  await session.refresh(instance)
200
  result = instance