Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -177,7 +177,6 @@ async def sms_posts(instance: ResultItem, idx: str = None, action: str = "add")
|
|
177 |
async with AsyncSession(sms_resource["engine"]) as session:
|
178 |
code = 1
|
179 |
error = None
|
180 |
-
result = instance.model_copy(deep=True)
|
181 |
existing = await session.get(instance.__class__, idx)
|
182 |
|
183 |
# For add action, do db operation if instance is not existing. Other actions, do db operation if instance exists in db
|
@@ -186,7 +185,7 @@ async def sms_posts(instance: ResultItem, idx: str = None, action: str = "add")
|
|
186 |
try:
|
187 |
if checker:
|
188 |
if action == "delete":
|
189 |
-
|
190 |
await session.commit()
|
191 |
else: # add or update use add
|
192 |
session.add(instance) # Not asynchronous
|
@@ -197,7 +196,7 @@ async def sms_posts(instance: ResultItem, idx: str = None, action: str = "add")
|
|
197 |
error = e
|
198 |
|
199 |
finally:
|
200 |
-
return await endpoint_output(
|
201 |
|
202 |
|
203 |
# @cache(expire=ONE_DAY_SEC, namespace='sms_gets') # Cache for 1 day
|
|
|
177 |
async with AsyncSession(sms_resource["engine"]) as session:
|
178 |
code = 1
|
179 |
error = None
|
|
|
180 |
existing = await session.get(instance.__class__, idx)
|
181 |
|
182 |
# For add action, do db operation if instance is not existing. Other actions, do db operation if instance exists in db
|
|
|
185 |
try:
|
186 |
if checker:
|
187 |
if action == "delete":
|
188 |
+
session.delete(instance)
|
189 |
await session.commit()
|
190 |
else: # add or update use add
|
191 |
session.add(instance) # Not asynchronous
|
|
|
196 |
error = e
|
197 |
|
198 |
finally:
|
199 |
+
return await endpoint_output(instance, code, error)
|
200 |
|
201 |
|
202 |
# @cache(expire=ONE_DAY_SEC, namespace='sms_gets') # Cache for 1 day
|