From 17c26c9fa9068868d41416baaddcb03819d56ed4 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Fri, 3 Mar 2023 16:43:27 -0700 Subject: [PATCH] Sub label filter fixes (#5602) * Fix list access issue * Specifically include item when in list or individual only * Formatting * Sort sub labels to ensure consistent list --- frigate/http.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/frigate/http.py b/frigate/http.py index 1649ab55e..01df6ed8a 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -322,7 +322,9 @@ def get_sub_labels(): sub_labels.remove(None) if split_joined: - for label in sub_labels: + original_labels = sub_labels.copy() + + for label in original_labels: if "," in label: sub_labels.remove(label) parts = label.split(",") @@ -331,6 +333,7 @@ def get_sub_labels(): if not (part.strip()) in sub_labels: sub_labels.append(part.strip()) + sub_labels.sort() return jsonify(sub_labels) @@ -638,7 +641,13 @@ def events(): sub_label_clauses.append((Event.sub_label.is_null())) for label in filtered_sub_labels: - sub_label_clauses.append((Event.sub_label.cast("text") % f"*{label}*")) + sub_label_clauses.append( + (Event.sub_label.cast("text") == label) + ) # include exact matches + + # include this label when part of a list + sub_label_clauses.append((Event.sub_label.cast("text") % f"*{label},*")) + sub_label_clauses.append((Event.sub_label.cast("text") % f"*, {label}*")) sub_label_clause = reduce(operator.or_, sub_label_clauses) clauses.append((sub_label_clause))