From 3b3529d9045ac0d706143ac1f44b39d10f286d8f Mon Sep 17 00:00:00 2001 From: Saisri24 Date: Fri, 24 Apr 2026 09:26:09 -0400 Subject: [PATCH 1/2] adding crosslist check so same time warnings doesnt come when crosslited --- backend/app/repositories/section.py | 16 +++++++++++++ backend/app/services/section.py | 7 +++++- backend/tests/test_section_service.py | 33 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/backend/app/repositories/section.py b/backend/app/repositories/section.py index 523a850..72f71c3 100644 --- a/backend/app/repositories/section.py +++ b/backend/app/repositories/section.py @@ -100,3 +100,19 @@ def double_booked(db: Session, assignments: list[FacultyAssignment], meeting_tim if section.time_block_id == meeting_time: return True return False + + +def crosslist_group_section_ids(db: Session, section_id: int) -> set[int]: + ids: set[int] = {section_id} + section = get_by_id(db, section_id) + if section is None: + return ids + + if section.crosslisted_section_id is not None: + ids.add(section.crosslisted_section_id) + + reverse = db.query(Section).filter(Section.crosslisted_section_id == section_id).first() + if reverse is not None: + ids.add(reverse.section_id) + + return ids diff --git a/backend/app/services/section.py b/backend/app/services/section.py index edea5e3..d644267 100644 --- a/backend/app/services/section.py +++ b/backend/app/services/section.py @@ -318,6 +318,7 @@ def error_check(db: Session, section: Section, updates: SectionUpdate | None = N return [] warnings = [] faculty_nuids = section_repo.get_faculty_assignmnets(db, section.section_id) + crosslist_ids = section_repo.crosslist_group_section_ids(db, section.section_id) if section.time_block_id is not None: schedule = schedule_repo.get_by_id(db, section.schedule_id) @@ -327,7 +328,11 @@ def error_check(db: Session, section: Section, updates: SectionUpdate | None = N warnings.append(WarningType.TIME_BLOCK_OVERLOAD) for nuid in faculty_nuids: - other_assignments = [a for a in faculty_repo.get_assignments(db, nuid, section.schedule_id) if a.section_id != section.section_id] + other_assignments = [ + a + for a in faculty_repo.get_assignments(db, nuid, section.schedule_id) + if a.section_id not in crosslist_ids + ] if section.time_block_id is not None: if not faculty_repo.find_meeting_time_preference(db, nuid, section.time_block_id): warnings.append(WarningType.UNPREFERENCED_TIME) diff --git a/backend/tests/test_section_service.py b/backend/tests/test_section_service.py index 7002690..406f2a8 100644 --- a/backend/tests/test_section_service.py +++ b/backend/tests/test_section_service.py @@ -397,6 +397,39 @@ def test_error_check_empty_faculty_nuids_no_warning(db_session): assert WarningType.FACULTY_OVERLOAD not in warnings +def test_error_check_crosslisted_sections_not_double_booked(db_session): + campus = _make_campus(db_session) + semester = _make_semester(db_session) + schedule = _make_schedule(db_session, campus, semester) + course = _make_course(db_session, name="CS 2500", code=2500) + tb = _make_time_block(db_session, campus) + faculty = _make_faculty(db_session, campus, nuid=1001, email="f1@test.edu") + + a = _make_section(db_session, schedule, course, tb, number=1) + b = _make_section(db_session, schedule, course, tb, number=2) + # Crosslist them as partners. + a.crosslisted_section_id = b.section_id + b.crosslisted_section_id = a.section_id + + db_session.add(FacultyAssignment(faculty_nuid=faculty.nuid, section_id=a.section_id)) + db_session.add(FacultyAssignment(faculty_nuid=faculty.nuid, section_id=b.section_id)) + db_session.commit() + + warnings_a = section_service.error_check(db_session, a, SectionUpdate(faculty_nuids=[faculty.nuid])) + warnings_b = section_service.error_check(db_session, b, SectionUpdate(faculty_nuids=[faculty.nuid])) + + assert WarningType.FACULTY_DOUBLE_BOOKED not in warnings_a + assert WarningType.FACULTY_DOUBLE_BOOKED not in warnings_b + + # A third, non-crosslisted section at the same time block should still trigger a real double-booking warning. + c = _make_section(db_session, schedule, course, tb, number=3) + db_session.add(FacultyAssignment(faculty_nuid=faculty.nuid, section_id=c.section_id)) + db_session.commit() + + warnings_c = section_service.error_check(db_session, c, SectionUpdate(faculty_nuids=[faculty.nuid])) + assert WarningType.FACULTY_DOUBLE_BOOKED in warnings_c + + # --------------------------------------------------------------------------- # update_section — basic behavior # --------------------------------------------------------------------------- From 8978f267af9007740b47aed121d574724f499288 Mon Sep 17 00:00:00 2001 From: Saisri24 Date: Fri, 24 Apr 2026 09:30:43 -0400 Subject: [PATCH 2/2] format --- backend/app/services/section.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/backend/app/services/section.py b/backend/app/services/section.py index d644267..7c15085 100644 --- a/backend/app/services/section.py +++ b/backend/app/services/section.py @@ -328,11 +328,7 @@ def error_check(db: Session, section: Section, updates: SectionUpdate | None = N warnings.append(WarningType.TIME_BLOCK_OVERLOAD) for nuid in faculty_nuids: - other_assignments = [ - a - for a in faculty_repo.get_assignments(db, nuid, section.schedule_id) - if a.section_id not in crosslist_ids - ] + other_assignments = [a for a in faculty_repo.get_assignments(db, nuid, section.schedule_id) if a.section_id not in crosslist_ids] if section.time_block_id is not None: if not faculty_repo.find_meeting_time_preference(db, nuid, section.time_block_id): warnings.append(WarningType.UNPREFERENCED_TIME)