Spaces:
Running
Running
Commit ·
902fb3c
1
Parent(s): 91ea556
fix(db_init): Remove async/await from synchronous database calls and update role field references
Browse files- Remove unnecessary await keyword from get_database() calls in db_init.py and main.py
- Update user role field references from "role" to "role_id" for consistency with schema
- Downgrade bcrypt dependency from 4.1.3 to 4.0.1 for compatibility
- Ensure database initialization properly handles synchronous database connections
- app/core/db_init.py +3 -3
- app/main.py +1 -1
- requirements.txt +1 -1
app/core/db_init.py
CHANGED
|
@@ -17,7 +17,7 @@ async def initialize_database():
|
|
| 17 |
logger.info("🔧 Initializing database...")
|
| 18 |
|
| 19 |
try:
|
| 20 |
-
db =
|
| 21 |
|
| 22 |
# Migrate existing data
|
| 23 |
await migrate_existing_users(db)
|
|
@@ -203,8 +203,8 @@ async def create_initial_users(db):
|
|
| 203 |
else:
|
| 204 |
# Update existing user if missing required fields
|
| 205 |
updates = {}
|
| 206 |
-
if "
|
| 207 |
-
updates["
|
| 208 |
if "status" not in existing:
|
| 209 |
updates["status"] = "active"
|
| 210 |
if "security_settings" not in existing:
|
|
|
|
| 17 |
logger.info("🔧 Initializing database...")
|
| 18 |
|
| 19 |
try:
|
| 20 |
+
db = get_database()
|
| 21 |
|
| 22 |
# Migrate existing data
|
| 23 |
await migrate_existing_users(db)
|
|
|
|
| 203 |
else:
|
| 204 |
# Update existing user if missing required fields
|
| 205 |
updates = {}
|
| 206 |
+
if "role_id" not in existing:
|
| 207 |
+
updates["role_id"] = user["role_id"]
|
| 208 |
if "status" not in existing:
|
| 209 |
updates["status"] = "active"
|
| 210 |
if "security_settings" not in existing:
|
app/main.py
CHANGED
|
@@ -78,7 +78,7 @@ async def check_db_status():
|
|
| 78 |
from app.nosql import get_database
|
| 79 |
from app.constants.collections import AUTH_SYSTEM_USERS_COLLECTION, AUTH_ACCESS_ROLES_COLLECTION, SCM_ACCESS_ROLES_COLLECTION
|
| 80 |
|
| 81 |
-
db =
|
| 82 |
|
| 83 |
users_count = await db[AUTH_SYSTEM_USERS_COLLECTION].count_documents({})
|
| 84 |
roles_count = await db[AUTH_ACCESS_ROLES_COLLECTION].count_documents({})
|
|
|
|
| 78 |
from app.nosql import get_database
|
| 79 |
from app.constants.collections import AUTH_SYSTEM_USERS_COLLECTION, AUTH_ACCESS_ROLES_COLLECTION, SCM_ACCESS_ROLES_COLLECTION
|
| 80 |
|
| 81 |
+
db = get_database()
|
| 82 |
|
| 83 |
users_count = await db[AUTH_SYSTEM_USERS_COLLECTION].count_documents({})
|
| 84 |
roles_count = await db[AUTH_ACCESS_ROLES_COLLECTION].count_documents({})
|
requirements.txt
CHANGED
|
@@ -9,7 +9,7 @@ redis==5.0.1
|
|
| 9 |
|
| 10 |
python-jose[cryptography]==3.3.0
|
| 11 |
passlib[bcrypt]==1.7.4
|
| 12 |
-
bcrypt==4.1
|
| 13 |
pydantic>=2.12.5,<3.0.0
|
| 14 |
pydantic-settings>=2.0.0
|
| 15 |
|
|
|
|
| 9 |
|
| 10 |
python-jose[cryptography]==3.3.0
|
| 11 |
passlib[bcrypt]==1.7.4
|
| 12 |
+
bcrypt==4.0.1
|
| 13 |
pydantic>=2.12.5,<3.0.0
|
| 14 |
pydantic-settings>=2.0.0
|
| 15 |
|