Skip to content

fix: restore listWithTeam query to include team events with userId set and add comprehensive tests#27752

Merged
keithwillcode merged 1 commit intomainfrom
devin/1770567962-fix-listwithteam-query
Feb 9, 2026
Merged

fix: restore listWithTeam query to include team events with userId set and add comprehensive tests#27752
keithwillcode merged 1 commit intomainfrom
devin/1770567962-fix-listwithteam-query

Conversation

@Ryukemeister
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a behavioral regression introduced in #27497 where the listWithTeam SQL query was changed to add AND "public"."EventType"."teamId" IS NULL to the first part of the UNION. This caused team event types with userId set (but no corresponding Membership row) to silently disappear from query results.

This PR:

  1. Removes the teamId IS NULL filter from Part 1 of the UNION, restoring the original behavior where all event types with userId = currentUser are returned (including team events where the user is the owner).
  2. Adds a LEFT JOIN users to Part 2 of the UNION so both parts produce identical username values for overlapping events, ensuring UNION deduplication works correctly.
  3. Adds 9 comprehensive integration tests covering previously untested edge cases.

Key scenarios now tested

Scenario Before this fix After this fix
Team event with userId set, user has no Membership ❌ Dropped silently ✅ Returned
User is both owner (userId) and team member (Membership) ✅ Returned (1 copy) ✅ Returned (1 copy, verified no duplication)
Managed child event type (parentId set, teamId null) Untested ✅ Returned
Team event with no userId (discovered via Membership) Untested ✅ Returned
username field populated for individual, null for team events Untested ✅ Verified
Unaccepted membership does not surface team events Untested ✅ Verified
User with zero event types Untested ✅ Returns empty array

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A — no documentation changes required.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  1. Run the integration tests:
    TZ=UTC VITEST_MODE=integration yarn test listWithTeam.handler.integration-test.ts
  2. Verify all 9 test cases pass, especially:
    • "should return team event types where userId is set but user has no membership" — this is the regression test
    • "should not duplicate events when user is both owner and team member" — validates UNION dedup

Human Review Checklist

  • Verify UNION deduplication: both UNION parts now JOIN to users on EventType.userId, so overlapping rows produce identical username values and are correctly deduped
  • Confirm that removing teamId IS NULL from Part 1 doesn't produce unexpected results for other consumers (useEventTypes hook in bookings, atoms API controller)
  • Validate the test for "team event where userId is set but no membership" correctly reproduces the regression scenario

Link to Devin run: https://app.devin.ai/sessions/db3ea4a75b23410080df845007f47c56
Requested by: @Ryukemeister

…t and add comprehensive tests

Co-Authored-By: rajiv@cal.com <sahalrajiv6900@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@Ryukemeister Ryukemeister marked this pull request as ready for review February 8, 2026 16:37
@graphite-app graphite-app bot added consumer core area: core, team members only labels Feb 8, 2026
@graphite-app graphite-app bot requested a review from a team February 8, 2026 16:37
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@keithwillcode keithwillcode enabled auto-merge (squash) February 9, 2026 11:28
@keithwillcode
Copy link
Copy Markdown
Contributor

Ran EXPLAIN ANALYZE for the query and it's high performance still.

@keithwillcode keithwillcode merged commit d4a0590 into main Feb 9, 2026
96 of 98 checks passed
@keithwillcode keithwillcode deleted the devin/1770567962-fix-listwithteam-query branch February 9, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

consumer core area: core, team members only ready-for-e2e size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants