Skip to content

Conversation

@ameliahsu
Copy link
Member

we were only returning open periods that started during/after query_start, which does not include open periods that started before query_start but were still ongoing during the query range

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 24, 2025
@codecov
Copy link

codecov bot commented Nov 24, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
23158 1 23157 178
View the top 1 failed test(s) by shortest run time
tests.sentry.workflow_engine.endpoints.test_organization_open_periods.OrganizationOpenPeriodsTest::test_open_periods_limit
Stack Traces | 3.02s run time
#x1B[1m#x1B[.../workflow_engine/endpoints/test_organization_open_periods.py#x1B[0m:285: in test_open_periods_limit
    assert resp["lastChecked"].replace(second=0, microsecond=0) == second_resolved_time.replace(
#x1B[1m#x1B[31mE   KeyError: 'lastChecked'#x1B[0m

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Comment on lines 159 to 166
group_open_periods = (
GroupOpenPeriod.objects.filter(
group=group,
date_started__lte=query_end,
)
.filter(Q(date_ended__gte=query_start) | Q(date_ended__isnull=True))
.order_by("-date_started")
)
Copy link
Member

Choose a reason for hiding this comment

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

I feel like it's a bit easier to grok if you phrase it as

"Either the end time is between the [start, end] or the start time is between [start, end]"

Suggested change
group_open_periods = (
GroupOpenPeriod.objects.filter(
group=group,
date_started__lte=query_end,
)
.filter(Q(date_ended__gte=query_start) | Q(date_ended__isnull=True))
.order_by("-date_started")
)
group_open_periods = GroupOpenPeriod.objects.filter(
Q(date_ended__lte=query_end) & Q(date_ended__gte=query_start)
| (Q(date_started__lte=query_end) & Q(date_started__gte=query_start)),
group=group,
).order_by("-date_started")

Copy link
Member Author

@ameliahsu ameliahsu Nov 24, 2025

Choose a reason for hiding this comment

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

unfortunately this doesn't account for open periods that extend beyond the query period in both directions 🥲

ex. if i have an open period from day 0 to day 7 and i query for day 2 to 3, then the open period wouldn't be returned

i'll update the comment to make it easier to grok the current logic

Copy link
Member

Choose a reason for hiding this comment

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

sadge

perhaps add this specific case as another condition to the query then?

Copy link
Member

Choose a reason for hiding this comment

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

alternatively, explain what cases the current query covers, I think that's what got me

@ameliahsu ameliahsu merged commit 88d2f92 into master Nov 25, 2025
67 checks passed
@ameliahsu ameliahsu deleted the mia/aci/fix-open-period-date-ranges branch November 25, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants