Spaces:
Running
Running
AuthorBot commited on
Commit ·
90769e9
1
Parent(s): 5ae645d
Fix: missing timezone import in superadmin grants + naive/aware datetime comparison crash
Browse files- app/superadmin/router.py +6 -6
app/superadmin/router.py
CHANGED
|
@@ -457,7 +457,7 @@ async def list_all_grants(
|
|
| 457 |
from sqlalchemy import select
|
| 458 |
from app.models.client_access import ClientAccess
|
| 459 |
from app.models.user import User
|
| 460 |
-
from datetime import datetime
|
| 461 |
|
| 462 |
result = await db.execute(
|
| 463 |
select(ClientAccess, User)
|
|
@@ -467,17 +467,17 @@ async def list_all_grants(
|
|
| 467 |
)
|
| 468 |
rows = result.all()
|
| 469 |
|
| 470 |
-
now = datetime.now(timezone.utc)
|
| 471 |
grants = []
|
| 472 |
for access, user in rows:
|
| 473 |
total_budget = access.token_budget + access.bonus_tokens
|
| 474 |
pct = round((access.tokens_used / total_budget * 100), 1) if total_budget > 0 else 0
|
| 475 |
exp = access.expires_at
|
| 476 |
-
#
|
|
|
|
| 477 |
if exp and exp.tzinfo is not None:
|
| 478 |
-
from datetime import timezone
|
| 479 |
exp = exp.replace(tzinfo=None)
|
| 480 |
-
is_expired = exp <
|
| 481 |
grants.append({
|
| 482 |
"grant_id": access.id,
|
| 483 |
"author_id": access.author_id,
|
|
@@ -536,7 +536,7 @@ async def get_author_embed_token(
|
|
| 536 |
from app.models.client_access import ClientAccess
|
| 537 |
from app.models.user import User
|
| 538 |
from app.core.access.token_crypto import create_subscription_token
|
| 539 |
-
from datetime import datetime
|
| 540 |
|
| 541 |
# Get author info
|
| 542 |
user = await db.get(User, author_id)
|
|
|
|
| 457 |
from sqlalchemy import select
|
| 458 |
from app.models.client_access import ClientAccess
|
| 459 |
from app.models.user import User
|
| 460 |
+
from datetime import datetime, timezone
|
| 461 |
|
| 462 |
result = await db.execute(
|
| 463 |
select(ClientAccess, User)
|
|
|
|
| 467 |
)
|
| 468 |
rows = result.all()
|
| 469 |
|
| 470 |
+
now = datetime.now(timezone.utc)
|
| 471 |
grants = []
|
| 472 |
for access, user in rows:
|
| 473 |
total_budget = access.token_budget + access.bonus_tokens
|
| 474 |
pct = round((access.tokens_used / total_budget * 100), 1) if total_budget > 0 else 0
|
| 475 |
exp = access.expires_at
|
| 476 |
+
# Make both naive for comparison (SQLite stores naive datetimes)
|
| 477 |
+
now_naive = now.replace(tzinfo=None)
|
| 478 |
if exp and exp.tzinfo is not None:
|
|
|
|
| 479 |
exp = exp.replace(tzinfo=None)
|
| 480 |
+
is_expired = exp < now_naive if exp else True
|
| 481 |
grants.append({
|
| 482 |
"grant_id": access.id,
|
| 483 |
"author_id": access.author_id,
|
|
|
|
| 536 |
from app.models.client_access import ClientAccess
|
| 537 |
from app.models.user import User
|
| 538 |
from app.core.access.token_crypto import create_subscription_token
|
| 539 |
+
from datetime import datetime, timezone
|
| 540 |
|
| 541 |
# Get author info
|
| 542 |
user = await db.get(User, author_id)
|