From ee6d5546750eb834c7436a563dbaefb27abccf57 Mon Sep 17 00:00:00 2001 From: Braden MacDonald Date: Fri, 20 Oct 2023 08:51:38 -0700 Subject: [PATCH] fix: fix sorting tags on MySQL --- openedx_tagging/core/tagging/models/base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openedx_tagging/core/tagging/models/base.py b/openedx_tagging/core/tagging/models/base.py index 5428f686..1262146c 100644 --- a/openedx_tagging/core/tagging/models/base.py +++ b/openedx_tagging/core/tagging/models/base.py @@ -466,10 +466,11 @@ def _get_filtered_tags_deep( # For a root tag, we want sort_key="RootValue" and for a depth=1 tag # we want sort_key="RootValue\tValue". The following does that, since # ConcatNull(...) returns NULL if any argument is NULL. - Coalesce(ConcatNull(F("parent__parent__parent__value"), Value("\t")), Value("")), - Coalesce(ConcatNull(F("parent__parent__value"), Value("\t")), Value("")), - Coalesce(ConcatNull(F("parent__value"), Value("\t")), Value("")), + ConcatNull(F("parent__parent__parent__value"), Value("\t")), + ConcatNull(F("parent__parent__value"), Value("\t")), + ConcatNull(F("parent__value"), Value("\t")), F("value"), + Value("\t"), # We also need the '\t' separator character at the end, or MySQL will sort things wrong output_field=models.CharField(), )) # Add the parent value