Skip to content
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

remove mysql leftover #10694

Merged
merged 7 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
manuel-sommer committed Dec 5, 2024

Verified

This commit was signed with the committer’s verified signature.
KyleFromNVIDIA Kyle Edwards
commit a94b64e8f232e88a1b9682ba656014695ee80854
13 changes: 1 addition & 12 deletions dojo/metrics/utils.py
Original file line number Diff line number Diff line change
@@ -537,18 +537,7 @@ def get_in_period_details(
).order_by("product_name")

# Approach to age determination is db-engine dependent
if "postgresql" in connection.settings_dict["ENGINE"]:
age_detail = findings.annotate(age=ExtractDay(Coalesce("mitigated", Now()) - F("date")))
elif "mysql" in connection.settings_dict["ENGINE"]:
# MySQL doesn't support durations natively and using an expression with subtraction yields unwanted results,
# so datediff() it is.
finding_table = Finding.objects.model._meta.db_table
age_detail = findings.annotate(
age=RawSQL(f"DATEDIFF(COALESCE({finding_table}.mitigated, CURRENT_TIMESTAMP), {finding_table}.date)", []),
)
else:
raise ValueError

age_detail = findings.annotate(age=ExtractDay(Coalesce("mitigated", Now()) - F("date")))
age_detail = age_detail.aggregate(
age_under_30=Sum(Case(When(age__lte=30, then=Value(1))), default=Value(0), output_field=IntegerField()),
age_31_60=Sum(Case(When(age__range=[31, 60], then=Value(1))), default=Value(0), output_field=IntegerField()),