Skip to content

feat(occurrences): Preprocess redirects#109616

Open
thetruecpaul wants to merge 1 commit intomasterfrom
cpaul/eap_occurrences/redirect_preprocess
Open

feat(occurrences): Preprocess redirects#109616
thetruecpaul wants to merge 1 commit intomasterfrom
cpaul/eap_occurrences/redirect_preprocess

Conversation

@thetruecpaul
Copy link
Contributor

We do not update EAP in the event of a group merge. Instead, we track the merge in our "Group Redirect" table.

This PR preprocesses EAP queries to account for the redirects, so users can always query and get all their relevant groups.

@thetruecpaul thetruecpaul requested a review from a team February 27, 2026 21:21
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 27, 2026

# Only need to update in the "new matches found" case.
if len(all_group_ids) > len(group_ids):
pieces.append(f"group_id:[{', '.join(str(gid) for gid in all_group_ids)}]")
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-deterministic set iteration produces unstable query output

Medium Severity

get_all_merged_group_ids returns a set, and iterating over it with ', '.join(str(gid) for gid in all_group_ids) produces group IDs in a non-deterministic order. The tests assert exact string equality (e.g., == "group_id:[1, 2, 3]"), which only passes due to CPython's implementation-specific hash ordering for small integers. With real (large) group IDs, the output order will vary across runs, making behavior unpredictable and tests flaky.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Query behavior should not depend on array ordering and the tests can keep using small numbers.

We do not update EAP in the event of a group merge. Instead, we track the merge in our "Group Redirect" table.

This PR preprocesses EAP queries to account for the redirects, so users can always query and get all their relevant groups.
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

all_group_ids = get_all_merged_group_ids({int(gid) for gid in group_ids})

# Only need to update in the "new matches found" case.
if len(all_group_ids) > len(group_ids):
Copy link
Contributor

Choose a reason for hiding this comment

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

List-vs-set length comparison can skip needed updates

Low Severity

The guard len(all_group_ids) > len(group_ids) compares the returned set length against the length of the original string list. Since the input to get_all_merged_group_ids is deduplicated via a set comprehension, if the original list had duplicates, len(group_ids) (list) can exceed len(all_group_ids) (set) even when new merged IDs were found, causing the update to be incorrectly skipped.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There shouldn't be duplicates in the passed-in input.

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.

1 participant