Skip to content

Commit 24f09af

Browse files
committed
cosmosdb unique index failures once again
1 parent f7fe39d commit 24f09af

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

backend/app.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ def create_unique_indexes_batch(collection, keys):
586586

587587
except Exception as e:
588588
logging.getLogger(__name__).error(f"Critical error in create_db_indexes: {e}")
589+
590+
# Ensure this runs even if previous blocks had partial failures (but not critical ones that skipped the whole block)
591+
# We put this in a separate try-except block to differentiate errors
592+
try:
589593
db.topics.create_index("banned_users")
590594

591595
# Posts collection indexes (within Topics)
@@ -763,8 +767,12 @@ def create_unique_indexes_batch(collection, keys):
763767
logger.info("Database indexes created successfully")
764768

765769
except Exception as e:
766-
logger.error(f"Failed to create database indexes: {e}")
767-
raise
770+
# Prevent crash on Cosmos DB unique index errors (Code 13) or other non-critical index failures
771+
# The application handles uniqueness checks at the model level (e.g. backend/models/user.py),
772+
# so missing DB unique constraints are acceptable for stability.
773+
logger.warning(f"Non-critical index creation failed: {e}. Continuing startup...")
774+
# Do not raise - allow server to start
775+
pass
768776

769777

770778
# Create global app instance for Gunicorn/production

0 commit comments

Comments
 (0)