fix(FN-011): wrap validate_connection in try/except, flush before return, remove unused import, document unique constraint deferral
Fusion-Task-Id: FN-011 Fusion-Task-Lineage: 4a9aca6f-9d91-43aa-8d2a-d59657c1541a
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import uuid
|
||||
|
||||
from pydantic import BaseModel
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.git.credentials import CredentialStorage, GitCredential
|
||||
@@ -50,7 +49,15 @@ class ConnectionManager:
|
||||
session.add(row)
|
||||
await session.flush()
|
||||
|
||||
status = self.provider.validate_connection(git_url, str(credential_id))
|
||||
try:
|
||||
status = self.provider.validate_connection(
|
||||
git_url, str(credential_id)
|
||||
)
|
||||
except Exception:
|
||||
row.connection_status = str(ConnectionStatus.error)
|
||||
await session.flush()
|
||||
raise RuntimeError("Connection validation failed")
|
||||
|
||||
if status == ConnectionStatus.connected:
|
||||
row.connection_status = str(ConnectionStatus.connected)
|
||||
else:
|
||||
@@ -58,7 +65,7 @@ class ConnectionManager:
|
||||
await session.flush()
|
||||
raise RuntimeError("Connection validation failed")
|
||||
|
||||
await session.refresh(row)
|
||||
await session.flush()
|
||||
return _map_row(row)
|
||||
|
||||
async def disconnect(
|
||||
|
||||
@@ -14,6 +14,9 @@ if TYPE_CHECKING:
|
||||
|
||||
class RepositoryConnection(Base, UUIDMixin, TimestampMixin):
|
||||
__tablename__ = "repository_connection"
|
||||
# NOTE: A partial unique index on (project_id, repository_id, provider_kind)
|
||||
# when repository_id IS NOT NULL is deferred for MVP. Duplicate connections
|
||||
# are acceptable until explicit disambiguation is required.
|
||||
|
||||
project_id: Mapped[uuid.UUID] = mapped_column(
|
||||
ForeignKey("project.id"), index=True
|
||||
|
||||
Reference in New Issue
Block a user