Skip to content

Commit 7533efc

Browse files
authored
Merge branch 'main' into chore/blocked-signal-in-1250
2 parents 7f1f582 + 636d4ce commit 7533efc

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,30 @@ def _parse_optional_date(value: str | None) -> date | None:
396396
except ValueError:
397397
return None
398398

399+
@staticmethod
400+
def _sanitize_date_range(
401+
date_start: date | None, date_end: date | None
402+
) -> tuple[date | None, date | None]:
403+
if date_end is not None and (date_start is None or date_end < date_start):
404+
return None, None
405+
return date_start, date_end
406+
407+
def normalize_affiliation_dates(
408+
self,
409+
affiliations: list[AffiliationContributorEntry] | None,
410+
) -> list[AffiliationContributorEntry] | None:
411+
if not affiliations:
412+
return affiliations
413+
414+
for entry in affiliations:
415+
for organization in entry.organizations:
416+
organization.date_start, organization.date_end = self._sanitize_date_range(
417+
organization.date_start,
418+
organization.date_end,
419+
)
420+
421+
return affiliations
422+
399423
@classmethod
400424
def group_parse_rows(
401425
cls, rows: list[AffiliationParseRow]
@@ -1029,6 +1053,8 @@ async def process_affiliations(
10291053
)
10301054
ai_cost += parse_cost
10311055

1056+
affiliations = self.normalize_affiliation_dates(affiliations)
1057+
10321058
if repository.parent_repo:
10331059
affiliations = await self.exclude_parent_repo_affiliations(
10341060
repository.parent_repo, affiliations

0 commit comments

Comments
 (0)