Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -516,18 +516,27 @@ def preprocess_text(text):
|
|
516 |
text = text.strip()
|
517 |
return text
|
518 |
|
519 |
-
|
|
|
|
|
520 |
def delete_record(container, id):
|
521 |
try:
|
522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
523 |
return True, f"Successfully deleted record with id: {id} 🗑️"
|
524 |
except exceptions.CosmosResourceNotFoundError:
|
525 |
return False, f"Record with id {id} not found. It may have been already deleted. 🕵️♂️"
|
526 |
except exceptions.CosmosHttpResponseError as e:
|
527 |
return False, f"HTTP error occurred: {str(e)} 🚨"
|
528 |
except Exception as e:
|
529 |
-
return False, f"An unexpected error occurred: {traceback.format_exc()} 😱"
|
530 |
-
|
|
|
531 |
|
532 |
# 🎭 Main function - "All the world's a stage, and all the code merely players" -Shakespeare, probably
|
533 |
def main():
|
|
|
516 |
text = text.strip()
|
517 |
return text
|
518 |
|
519 |
+
|
520 |
+
|
521 |
+
# 🗑️ Delete record - Handling partition key correctly
|
522 |
def delete_record(container, id):
|
523 |
try:
|
524 |
+
# Retrieve the document to ensure it exists and get the partition key
|
525 |
+
doc = container.read_item(item=id, partition_key=id) # Assuming 'id' is the partition key
|
526 |
+
# If your partition key is something else, you need to pass it explicitly here:
|
527 |
+
# doc = container.read_item(item=id, partition_key=doc['partition_key_field'])
|
528 |
+
|
529 |
+
# Now proceed with the deletion
|
530 |
+
container.delete_item(item=id, partition_key=doc['id']) # If 'id' is partition key
|
531 |
return True, f"Successfully deleted record with id: {id} 🗑️"
|
532 |
except exceptions.CosmosResourceNotFoundError:
|
533 |
return False, f"Record with id {id} not found. It may have been already deleted. 🕵️♂️"
|
534 |
except exceptions.CosmosHttpResponseError as e:
|
535 |
return False, f"HTTP error occurred: {str(e)} 🚨"
|
536 |
except Exception as e:
|
537 |
+
return False, f"An unexpected error occurred: {traceback.format_exc()} 😱"
|
538 |
+
|
539 |
+
|
540 |
|
541 |
# 🎭 Main function - "All the world's a stage, and all the code merely players" -Shakespeare, probably
|
542 |
def main():
|