Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -177,6 +177,7 @@ 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 |
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,18 +186,19 @@ async def sms_posts(instance: ResultItem, idx: str = None, action: str = "add")
|
|
185 |
try:
|
186 |
if checker:
|
187 |
if action == "delete":
|
188 |
-
session.delete(instance)
|
|
|
189 |
else: # add or update use add
|
190 |
-
session.add(instance)
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
except Exception as e:
|
195 |
code = 0
|
196 |
error = e
|
197 |
|
198 |
finally:
|
199 |
-
return await endpoint_output(
|
200 |
|
201 |
|
202 |
# @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 |
+
result = None
|
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 |
try:
|
187 |
if checker:
|
188 |
if action == "delete":
|
189 |
+
session.delete(instance) # Not 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
|
196 |
except Exception as e:
|
197 |
code = 0
|
198 |
error = e
|
199 |
|
200 |
finally:
|
201 |
+
return await endpoint_output(result, code, error)
|
202 |
|
203 |
|
204 |
# @cache(expire=ONE_DAY_SEC, namespace='sms_gets') # Cache for 1 day
|