Skip to content

fix: return empty activity channels when no subprojects are found - #4246

Merged
skwowet merged 1 commit into
mainfrom
fix/activity-channels-empty-subproject-expansion
Jun 22, 2026
Merged

fix: return empty activity channels when no subprojects are found#4246
skwowet merged 1 commit into
mainfrom
fix/activity-channels-empty-subproject-expansion

Conversation

@skwowet

@skwowet skwowet commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes a 500 on GET /activity/channel after moving segment expansion out of middleware. When the current project scope expands to zero active subprojects, the handler now returns an empty channel map instead of running SQL with segmentId IN ().

Changes

  • activityService.findActivityChannels — return {} when getSegmentSubprojectIds yields no IDs (same pattern as activity/query for empty expansion).
  • segmentRepository.fetchTenantActivityChannels — early return {} when segmentIds is empty, so no caller can generate invalid IN () SQL.

Context

With the middleware refactor, /activity/channel expands segments at the call site instead of relying on pre-expanded currentSegments or the old all-tenant-subprojects fallback. Expansion can legitimately be empty (e.g. project group with no active subprojects, or segment context not ready). Activities already handled this; channels did not.

…ubprojects

Avoid invalid `segmentId IN ()` SQL when project scope expands to zero
active subprojects after moving expansion out of middleware.

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@skwowet skwowet self-assigned this Jun 22, 2026
Copilot AI review requested due to automatic review settings June 22, 2026 09:10
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@skwowet
skwowet merged commit bb316cd into main Jun 22, 2026
14 checks passed
@skwowet
skwowet deleted the fix/activity-channels-empty-subproject-expansion branch June 22, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a backend 500 on GET /activity/channel by handling the “segment expansion yields zero subprojects” case safely, avoiding invalid SQL like segmentId IN () and returning an empty channel map instead.

Changes:

  • Return {} from ActivityService.findActivityChannels() when getSegmentSubprojectIds(...) returns no IDs.
  • Add a defensive early return {} in SegmentRepository.fetchTenantActivityChannels(...) when called with an empty segmentIds array.

Metadata note (repo workflow):

  • The PR title does not include a JIRA key in the required format type: description (CM-XXX) (see .claude/rules/commit-workflow.md:52-56). CI won’t fail (neutral check), but repo policy expects it.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
backend/src/services/activityService.ts Short-circuits /activity/channel to return {} when segment expansion is empty, preventing downstream invalid queries.
backend/src/database/repositories/segmentRepository.ts Adds a guard clause to avoid generating invalid IN () SQL when segmentIds is empty.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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