Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -170,15 +170,18 @@ def update_record(container, updated_record):
|
|
170 |
except Exception as e:
|
171 |
return False, f"Error: {traceback.format_exc()} ๐ฑ"
|
172 |
|
173 |
-
# ๐๏ธ Delete
|
174 |
def delete_record(container, record):
|
175 |
try:
|
176 |
container.delete_item(item=record['id'], partition_key=record['id'])
|
177 |
-
return True, f"
|
178 |
except exceptions.CosmosHttpResponseError as e:
|
|
|
|
|
|
|
179 |
return False, f"HTTP error: {str(e)} ๐จ"
|
180 |
except Exception as e:
|
181 |
-
return False, f"
|
182 |
|
183 |
# ๐พ Save a new document to Cosmos DB with extra fields
|
184 |
def save_to_cosmos_db(container, query, response1, response2):
|
|
|
170 |
except Exception as e:
|
171 |
return False, f"Error: {traceback.format_exc()} ๐ฑ"
|
172 |
|
173 |
+
# ๐๏ธ Delete record โ now treats 404 as success
|
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):
|