Skip to content

adding crosslist check so same time warnings doesnt come when crosslisted#76

Merged
BeWelsh merged 2 commits into
mainfrom
crosslist-warnings-fix
Apr 24, 2026
Merged

adding crosslist check so same time warnings doesnt come when crosslisted#76
BeWelsh merged 2 commits into
mainfrom
crosslist-warnings-fix

Conversation

@Saisri24
Copy link
Copy Markdown
Collaborator

@Saisri24 Saisri24 commented Apr 24, 2026

Description

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (code improvement without changing functionality)
  • Documentation update
  • Configuration/infrastructure change
  • Performance improvement
  • Test coverage improvement

What Changed?

Testing & Validation

How this was tested

Screenshots/Recordings

Unfinished Work & Known Issues

  • None, this PR is complete and production-ready
  • The following items are intentionally deferred:



Notes & Nuances



Reviewer Notes

  • Areas needing extra attention: ...
  • Questions for reviewers: ...

Summary by CodeRabbit

  • Bug Fixes
    • Faculty members assigned to crosslisted sections no longer receive incorrect double-booking warnings. The system now properly recognizes when sections are crosslisted with one another and excludes them from scheduling conflict detection. This ensures more accurate calculations of faculty workload and improves identification of genuine scheduling conflicts across the platform.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

Warning

Rate limit exceeded

@Saisri24 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 56 minutes and 15 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 56 minutes and 15 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d15a1502-b559-4c21-86b0-47d161472884

📥 Commits

Reviewing files that changed from the base of the PR and between 3b3529d and 8978f26.

📒 Files selected for processing (1)
  • backend/app/services/section.py

Walkthrough

A new repository function computes section IDs within a crosslisted group by querying forward and reverse crosslist relationships. The section service now uses this to exclude crosslisted sections from faculty double-booking checks, preventing false warnings when the same faculty teaches linked sections in the same time block.

Changes

Cohort / File(s) Summary
Repository Helper
backend/app/repositories/section.py
Introduces crosslist_group_section_ids function to retrieve all section IDs in a crosslisted group by following forward and reverse crosslisted_section_id relationships.
Service Logic
backend/app/services/section.py
Updates error_check to query the crosslist group for a section and exclude those assignments when calculating faculty overlap and double-booking, allowing same faculty in linked sections without warnings.
Test Coverage
backend/tests/test_section_service.py
Adds test validating that error_check does not report FACULTY_DOUBLE_BOOKED for crosslisted sections with shared faculty, but does report it for non-crosslisted sections in the same time block.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Service as Section Service
    participant Repo as Section Repository
    participant DB as Database

    Client->>Service: error_check(section_id)
    Service->>Repo: crosslist_group_section_ids(section_id)
    Repo->>DB: Query section & crosslisted_section_id
    DB-->>Repo: Section record
    Repo->>DB: Query reverse crosslist match
    DB-->>Repo: Matching sections
    Repo-->>Service: crosslist_group_ids (set)
    Service->>DB: Query faculty assignments
    DB-->>Service: All assignments for faculty
    Service->>Service: Filter: exclude assignments in crosslist_group
    Service->>Service: Check for overlaps in remaining assignments
    Service-->>Client: Validation warnings (or none)
Loading

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A crosslist magic we now weave,
When sections dance and faculty breathe,
No warnings cry when linked they be,
Together teaching—wild and free!
The rabbit hops with joy, you see! 🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description template is present but entirely unfilled—no description, type of change, details of what changed, testing methodology, or any other content has been provided. Complete the PR description with: a clear explanation of the crosslist check logic, the type of change (appears to be a bug fix), specific files/functions modified, and how the changes were tested.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding a crosslist check to prevent false 'same time' warnings for crosslisted sections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch crosslist-warnings-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/app/services/section.py (1)

330-345: ⚠️ Potential issue | 🟠 Major

Crosslist exclusion unintentionally skews FACULTY_OVERLOAD accounting.

other_assignments is reused for the FACULTY_OVERLOAD check at Line 344, not just double_booked. Excluding the whole crosslist group here makes the reported load depend on which section you're evaluating:

  • From a crosslisted section A (partner B), assignments to A and B are both filtered out, so len(other_assignments) + 1 counts the A/B pair as 1 toward the load.
  • From an unrelated section C taught by the same faculty, A and B are both kept, so the pair counts as 2 toward the load.

So a faculty teaching a crosslisted pair (A,B) + one standalone C with max_load=2 will produce no overload warning from A or B but will produce FACULTY_OVERLOAD when evaluating C — results are asymmetric and order-of-evaluation dependent. Earlier (pre-change) behavior was symmetric because only the current section row was excluded.

Consider splitting the filter so the crosslist group exclusion only applies to the double-booking check, and the load count uses one assignment per crosslist group. Something along these lines:

♻️ Suggested shape
-        other_assignments = [
-            a
-            for a in faculty_repo.get_assignments(db, nuid, section.schedule_id)
-            if a.section_id not in crosslist_ids
-        ]
+        all_assignments = faculty_repo.get_assignments(db, nuid, section.schedule_id)
+        # For double-booking, ignore everything in the current crosslist group.
+        non_crosslisted_assignments = [a for a in all_assignments if a.section_id not in crosslist_ids]
+        # For load, collapse each crosslist group (including the current one) to a single entry.
+        seen_groups: set[frozenset[int]] = set()
+        load_count = 0
+        for a in all_assignments:
+            group = frozenset(section_repo.crosslist_group_section_ids(db, a.section_id))
+            if group in seen_groups:
+                continue
+            seen_groups.add(group)
+            load_count += 1
         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)
-            if section_repo.double_booked(db, other_assignments, section.time_block_id):
+            if section_repo.double_booked(db, non_crosslisted_assignments, section.time_block_id):
                 warnings.append(WarningType.FACULTY_DOUBLE_BOOKED)
         if not faculty_repo.find_course_preference(db, nuid, section.course_id):
             warnings.append(WarningType.UNPREFERENCED_COURSE)
         f = faculty_repo.get_by_nuid(db, nuid)
-        if len(other_assignments) + 1 > f.max_load:
+        if load_count > f.max_load:
             warnings.append(WarningType.FACULTY_OVERLOAD)

(The per-assignment lookup is O(N) queries — if that's a concern, compute crosslist groups once per schedule upstream.)

Worth adding a test for the asymmetric case (crosslisted pair + standalone third section, max_load=2) to lock behavior down.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/app/services/section.py` around lines 330 - 345, The FACULTY_OVERLOAD
miscounts because other_assignments is filtered by crosslist_ids for the
double-booked check and then reused for the load check; change the code to build
two separate collections from faculty_repo.get_assignments(db, nuid,
section.schedule_id): 1) assignments_for_doublebook = assignments excluding any
assignment whose section_id is in crosslist_ids (used only with
section_repo.double_booked), and 2) assignments_for_load = assignments excluding
only the current section (e.g., a.section_id == section.id) and then
collapse/group assignments that belong to the same crosslist group into a single
representative before counting; then use len(grouped_assignments) + 1 vs
f.max_load to decide WarningType.FACULTY_OVERLOAD while leaving the
double-booking logic using assignments_for_doublebook and
section_repo.double_booked unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/app/services/section.py`:
- Line 321: The file app/services/section.py fails ruff formatting; run the
formatter and commit the changes: run `ruff format app/services/section.py` (or
your editor's ruff integration) to reformat the file, verify the change around
the line that calls section_repo.crosslist_group_section_ids (inside the
function where crosslist_ids is assigned), and include the reformatted file in
your commit so `ruff format --check` passes in CI.

---

Outside diff comments:
In `@backend/app/services/section.py`:
- Around line 330-345: The FACULTY_OVERLOAD miscounts because other_assignments
is filtered by crosslist_ids for the double-booked check and then reused for the
load check; change the code to build two separate collections from
faculty_repo.get_assignments(db, nuid, section.schedule_id): 1)
assignments_for_doublebook = assignments excluding any assignment whose
section_id is in crosslist_ids (used only with section_repo.double_booked), and
2) assignments_for_load = assignments excluding only the current section (e.g.,
a.section_id == section.id) and then collapse/group assignments that belong to
the same crosslist group into a single representative before counting; then use
len(grouped_assignments) + 1 vs f.max_load to decide
WarningType.FACULTY_OVERLOAD while leaving the double-booking logic using
assignments_for_doublebook and section_repo.double_booked unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2b49fc4e-1ee5-4a30-8b49-d1d2ea789270

📥 Commits

Reviewing files that changed from the base of the PR and between 5e43fe0 and 3b3529d.

📒 Files selected for processing (3)
  • backend/app/repositories/section.py
  • backend/app/services/section.py
  • backend/tests/test_section_service.py

Comment thread backend/app/services/section.py
Copy link
Copy Markdown
Collaborator

@BeWelsh BeWelsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@BeWelsh BeWelsh merged commit 99769d6 into main Apr 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants