Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -170,19 +170,20 @@ def update_record(container, updated_record):
|
|
| 170 |
except Exception as e:
|
| 171 |
return False, f"Error: {traceback.format_exc()} ๐ฑ"
|
| 172 |
|
| 173 |
-
# ๐๏ธ Delete record โ now
|
| 174 |
def delete_record(container, record):
|
| 175 |
try:
|
| 176 |
container.delete_item(item=record['id'], partition_key=record['id'])
|
| 177 |
return True, f"Record {record['id']} successfully deleted. ๐๏ธ"
|
|
|
|
|
|
|
|
|
|
| 178 |
except exceptions.CosmosHttpResponseError as e:
|
| 179 |
-
# If the document is not found, consider it already deleted
|
| 180 |
-
if e.status_code == 404:
|
| 181 |
-
return True, f"Record {record['id']} not found (already deleted). ๐๏ธ"
|
| 182 |
return False, f"HTTP error: {str(e)} ๐จ"
|
| 183 |
except Exception as e:
|
| 184 |
return False, f"Unexpected error: {traceback.format_exc()} ๐ฑ"
|
| 185 |
|
|
|
|
| 186 |
# ๐พ Save a new document to Cosmos DB with extra fields
|
| 187 |
def save_to_cosmos_db(container, query, response1, response2):
|
| 188 |
try:
|
|
|
|
| 170 |
except Exception as e:
|
| 171 |
return False, f"Error: {traceback.format_exc()} ๐ฑ"
|
| 172 |
|
| 173 |
+
# ๐๏ธ Delete record โ now explicitly catches resource not found errors
|
| 174 |
def delete_record(container, record):
|
| 175 |
try:
|
| 176 |
container.delete_item(item=record['id'], partition_key=record['id'])
|
| 177 |
return True, f"Record {record['id']} successfully deleted. ๐๏ธ"
|
| 178 |
+
except exceptions.CosmosResourceNotFoundError:
|
| 179 |
+
# Document does not exist โ treat as deleted
|
| 180 |
+
return True, f"Record {record['id']} not found (already deleted). ๐๏ธ"
|
| 181 |
except exceptions.CosmosHttpResponseError as e:
|
|
|
|
|
|
|
|
|
|
| 182 |
return False, f"HTTP error: {str(e)} ๐จ"
|
| 183 |
except Exception as e:
|
| 184 |
return False, f"Unexpected error: {traceback.format_exc()} ๐ฑ"
|
| 185 |
|
| 186 |
+
|
| 187 |
# ๐พ Save a new document to Cosmos DB with extra fields
|
| 188 |
def save_to_cosmos_db(container, query, response1, response2):
|
| 189 |
try:
|