-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(aci): decouple detector from workflowfirehistory in API #102918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| from sentry.api.serializers.models.group import BaseGroupSerializerResponse | ||
| from sentry.models.group import Group | ||
| from sentry.utils.cursors import Cursor, CursorResult | ||
| from sentry.workflow_engine.models import Detector, Workflow, WorkflowFireHistory | ||
| from sentry.workflow_engine.models import Detector, DetectorGroup, Workflow, WorkflowFireHistory | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
|
|
@@ -118,13 +118,22 @@ def fetch_workflow_groups_paginated( | |
|
|
||
| # subquery that retrieves row with the largest date in a group | ||
| group_max_dates = filtered_history.filter(group=OuterRef("group")).order_by("-date_added")[:1] | ||
|
|
||
| # Subquery to get the detector_id from DetectorGroup. | ||
| # The detector does not currently need to be connected to the workflow. | ||
| detector_subquery = DetectorGroup.objects.filter( | ||
| group=OuterRef("group"), | ||
| ).values( | ||
| "detector_id" | ||
| )[:1] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens with this subquery when there isn't a DetectorGroup? Groups do exist visibly before DetectorGroup for a short period, but also our backfill isn't quite finished.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will return None and the frontend will assume it's associated with the issue stream detector (maybe not implemented yet but it will) |
||
|
|
||
| qs = ( | ||
| filtered_history.select_related("group", "detector") | ||
| filtered_history.select_related("group") | ||
| .values("group") | ||
| .annotate(count=Count("group")) | ||
| .annotate(event_id=Subquery(group_max_dates.values("event_id"))) | ||
| .annotate(last_triggered=Max("date_added")) | ||
| .annotate(detector_id=Subquery(group_max_dates.values("detector_id"))) | ||
| .annotate(detector_id=Subquery(detector_subquery)) | ||
| ) | ||
|
|
||
| # Count distinct groups for pagination | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
High severity vulnerability may affect your project—review required:
Line 125 lists a dependency (django) with a known High severity vulnerability.
ℹ️ Why this matters
Affected versions of Django are vulnerable to Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'). SQL injection in Django's ORM column aliases: when using QuerySet.annotate(), QuerySet.alias(), QuerySet.aggregate(), or QuerySet.extra() with dictionary expansion (**kwargs), the dictionary keys are used unescaped as SQL column aliases. On MySQL and MariaDB backends, an attacker who can influence those keys (for example, by passing a crafted dict of annotations) can inject arbitrary SQL into the generated query.
References: GHSA, CVE
To resolve this comment:
Check if you are using Django with MySQL or MariaDB.
/fp we don't use this [condition]💬 Ignore this finding
To ignore this, reply with:
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasonsYou can view more details on this finding in the Semgrep AppSec Platform here.