Skip to content

Commit f229bd4

Browse files
remyluslosiusclaude
andcommitted
fix(backend): Add integer-to-UUID conversion for GET/PUT/DELETE credential endpoints
Frontend sends integer IDs (for backward compatibility) but backend expects UUIDs. Added find_uuid_by_int() conversion in: - get_system_credential() - update_system_credential() - delete_system_credential() Fixes error: 'invalid input syntax for type uuid: "1547335328"' Now all three endpoints properly convert integer IDs to UUIDs before querying database. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent da531d7 commit f229bd4

1 file changed

Lines changed: 39 additions & 9 deletions

File tree

backend/app/routes/system_settings_unified.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,24 @@ async def create_system_credential(
257257
@require_permission(Permission.SYSTEM_CREDENTIALS)
258258
async def get_system_credential(
259259
request: Request,
260-
credential_id: str, # WEEK 2 MIGRATION: Changed from int to str (UUID)
260+
credential_id: str, # Frontend sends integer ID, need to convert to UUID
261261
db: Session = Depends(get_db),
262262
current_user: dict = Depends(get_current_user),
263263
):
264264
"""Get specific system credential by ID"""
265265
try:
266-
# WEEK 2 MIGRATION: credential_id is now UUID string
267-
uuid_id = credential_id
266+
# Convert integer ID from frontend to UUID
267+
try:
268+
external_id = int(credential_id)
269+
uuid_id = find_uuid_by_int(db, external_id)
270+
if not uuid_id:
271+
raise HTTPException(
272+
status_code=status.HTTP_404_NOT_FOUND,
273+
detail=f"Credential not found for ID {credential_id}",
274+
)
275+
except ValueError:
276+
# If it's already a UUID string, use it directly
277+
uuid_id = credential_id
268278

269279
# Get credential using unified service
270280
encryption_service: EncryptionService = request.app.state.encryption_service
@@ -347,15 +357,25 @@ async def get_default_system_credential(
347357
@require_permission(Permission.SYSTEM_CREDENTIALS)
348358
async def update_system_credential(
349359
request: Request,
350-
credential_id: str, # WEEK 2 MIGRATION: Changed from int to str (UUID)
360+
credential_id: str, # Frontend sends integer ID, need to convert to UUID
351361
credential_update: SystemCredentialsUpdate,
352362
db: Session = Depends(get_db),
353363
current_user: dict = Depends(get_current_user),
354364
):
355365
"""Update system credential (Note: Currently creates new due to unified credentials architecture)"""
356366
try:
357-
# WEEK 2 MIGRATION: credential_id is now UUID string from v2 API
358-
uuid_id = credential_id
367+
# Convert integer ID from frontend to UUID
368+
try:
369+
external_id = int(credential_id)
370+
uuid_id = find_uuid_by_int(db, external_id)
371+
if not uuid_id:
372+
raise HTTPException(
373+
status_code=status.HTTP_404_NOT_FOUND,
374+
detail=f"Credential not found for ID {credential_id}",
375+
)
376+
except ValueError:
377+
# If it's already a UUID string, use it directly
378+
uuid_id = credential_id
359379

360380
encryption_service: EncryptionService = request.app.state.encryption_service
361381
auth_service = get_auth_service(db, encryption_service)
@@ -498,14 +518,24 @@ async def update_system_credential(
498518
@require_permission(Permission.SYSTEM_CREDENTIALS)
499519
async def delete_system_credential(
500520
request: Request,
501-
credential_id: str, # WEEK 2 MIGRATION: Changed from int to str (UUID)
521+
credential_id: str, # Frontend sends integer ID, need to convert to UUID
502522
db: Session = Depends(get_db),
503523
current_user: dict = Depends(get_current_user),
504524
):
505525
"""Delete system credential"""
506526
try:
507-
# WEEK 2 MIGRATION: credential_id is now UUID string from v2 API
508-
uuid_id = credential_id
527+
# Convert integer ID from frontend to UUID
528+
try:
529+
external_id = int(credential_id)
530+
uuid_id = find_uuid_by_int(db, external_id)
531+
if not uuid_id:
532+
raise HTTPException(
533+
status_code=status.HTTP_404_NOT_FOUND,
534+
detail=f"Credential not found for ID {credential_id}",
535+
)
536+
except ValueError:
537+
# If it's already a UUID string, use it directly
538+
uuid_id = credential_id
509539

510540
# Delete using unified service
511541
encryption_service: EncryptionService = request.app.state.encryption_service

0 commit comments

Comments
 (0)