Skip to content

Commit d88bcad

Browse files
committed
fix: affiliation registry writes and expected-run reporting
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent ecd783a commit d88bcad

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

services/apps/git_integration/src/crowdgit/database/crud.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ async def upsert_repo_affiliation_registry(registry: RepoAffiliationRegistry) ->
546546
INSERT INTO git."repoAffiliationRegistry" (
547547
"repoId", "filePath", "fileHash", "status", "snapshot", "lastRunAt", "updatedAt"
548548
)
549-
VALUES ($1, $2, $3, $4, $5, NOW(), NOW())
549+
VALUES ($1, $2, $3, $4, $5::jsonb, NOW(), NOW())
550550
ON CONFLICT ("repoId") DO UPDATE SET
551551
"filePath" = EXCLUDED."filePath",
552552
"fileHash" = EXCLUDED."fileHash",
@@ -576,7 +576,8 @@ async def find_many_member_ids_by_identities(identities: list[dict]) -> list[dic
576576
param_index = 1
577577
for idx, identity in enumerate(identities):
578578
values_parts.append(
579-
f"(${param_index}, ${param_index + 1}, ${param_index + 2}, ${param_index + 3}, ${param_index + 4})"
579+
f"(${param_index}::int, ${param_index + 1}::text, ${param_index + 2}::boolean,"
580+
f" ${param_index + 3}::text, ${param_index + 4}::text)"
580581
)
581582
params.extend(
582583
[
@@ -638,7 +639,8 @@ async def find_many_organization_ids_by_identities(identities: list[dict]) -> li
638639
param_index = 1
639640
for idx, identity in enumerate(identities):
640641
values_parts.append(
641-
f"(${param_index}, ${param_index + 1}, ${param_index + 2}, ${param_index + 3})"
642+
f"(${param_index}::int, ${param_index + 1}::text,"
643+
f" ${param_index + 2}::boolean, ${param_index + 3}::text)"
642644
)
643645
params.extend(
644646
[

services/apps/git_integration/src/crowdgit/models/affiliation_info.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime
55
from typing import Any
66

7+
import orjson
78
from loguru import logger
89
from pydantic import BaseModel, TypeAdapter, ValidationError
910

@@ -71,6 +72,14 @@ def from_db(cls, db_data: dict[str, Any]) -> RepoAffiliationRegistry:
7172

7273
@staticmethod
7374
def _parse_snapshot(snapshot) -> list[AffiliationInfoItem] | None:
75+
if isinstance(snapshot, str | bytes):
76+
try:
77+
snapshot = orjson.loads(snapshot)
78+
except orjson.JSONDecodeError as error:
79+
logger.warning(
80+
f"Invalid affiliation snapshot JSON in registry, will re-parse: {error}"
81+
)
82+
return None
7483
if isinstance(snapshot, dict) and "affiliations" in snapshot:
7584
snapshot = snapshot["affiliations"]
7685
try:
@@ -79,7 +88,7 @@ def _parse_snapshot(snapshot) -> list[AffiliationInfoItem] | None:
7988
logger.warning(f"Invalid affiliation snapshot in registry, will re-parse: {error}")
8089
return None
8190

82-
def snapshot_for_db(self) -> list[dict] | None:
91+
def snapshot_for_db(self) -> str | None:
8392
if self.snapshot is None:
8493
return None
85-
return [item.model_dump() for item in self.snapshot]
94+
return orjson.dumps([item.model_dump() for item in self.snapshot]).decode()

services/apps/git_integration/src/crowdgit/services/affiliation/affiliation_service.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -858,21 +858,13 @@ async def process_affiliations(
858858
self.logger.info(f"Finished with {len(affiliations)} rows from {latest_file_path}")
859859

860860
except AffiliationIntervalNotElapsedError as e:
861-
execution_status = ExecutionStatus.FAILURE
862-
error_message = e.error_message
863-
error_code = e.error_code.value
861+
self.logger.info(e.error_message)
864862

865863
except AffiliationFileNotFoundError as e:
866-
execution_status = ExecutionStatus.FAILURE
867-
error_message = e.error_message
868-
error_code = e.error_code.value
869864
ai_cost = e.ai_cost
870-
self.logger.info(error_message)
865+
self.logger.info(e.error_message)
871866

872867
except AffiliationAnalysisError as e:
873-
execution_status = ExecutionStatus.FAILURE
874-
error_message = e.error_message
875-
error_code = e.error_code.value
876868
await upsert_repo_affiliation_registry(
877869
RepoAffiliationRegistry(
878870
repo_id=repository.id,
@@ -888,7 +880,13 @@ async def process_affiliations(
888880
else (registry.snapshot if registry else None),
889881
)
890882
)
891-
self.logger.warning(error_message)
883+
if e.retain_file_hash:
884+
self.logger.info(e.error_message)
885+
else:
886+
execution_status = ExecutionStatus.FAILURE
887+
error_message = e.error_message
888+
error_code = e.error_code.value
889+
self.logger.warning(error_message)
892890

893891
except Exception as e:
894892
execution_status = ExecutionStatus.FAILURE

0 commit comments

Comments
 (0)