File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments