Repository: DDMAL/CantusDB

Issue:
Error preventing us from updating Django to 4.2.1
I'm trying to update Django to the latest version, `4.2.1`. When I do, and then run `test_views`, I get ~20 errors. The last errors all belong to ChantSearchViewTest (VSCode is discarding the beginning of the test summary, because too much text is being output to the terminal). Here's the traceback for the final failure:

```
======================================================================
ERROR: test_volpiano_column (main_app.tests.test_views.ChantSearchViewTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/code/django/cantusdb_project/main_app/tests/test_views.py", line 1049, in test_volpiano_column
    response = self.client.get(
  File "/usr/local/lib/python3.9/site-packages/django/test/client.py", line 927, in get
    response = super().get(path, data=data, secure=secure, headers=headers, **extra)
  File "/usr/local/lib/python3.9/site-packages/django/test/client.py", line 457, in get
    return self.generic(
  File "/usr/local/lib/python3.9/site-packages/django/test/client.py", line 609, in generic
    return self.request(**r)
  File "/usr/local/lib/python3.9/site-packages/django/test/client.py", line 891, in request
    self.check_exception(response)
  File "/usr/local/lib/python3.9/site-packages/django/test/client.py", line 738, in check_exception
    raise exc_value
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 220, in _get_response
    response = response.render()
  File "/usr/local/lib/python3.9/site-packages/django/template/response.py", line 114, in render
    self.content = self.rendered_content
  File "/usr/local/lib/python3.9/site-packages/django/template/response.py", line 92, in rendered_content
    return template.render(context, self._request)
  File "/usr/local/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 175, in render
    return self._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/test/utils.py", line 112, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 157, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/test/utils.py", line 112, in instrumented_test_render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 63, in render
    result = block.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 1005, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 1005, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 966, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/defaulttags.py", line 320, in render
    if match:
  File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 412, in __bool__
    self._fetch_all()
  File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 1881, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 208, in __iter__
    for row in compiler.results_iter(
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1511, in results_iter
    results = self.execute_sql(
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1547, in execute_sql
    sql, params = self.as_sql()
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 734, in as_sql
    extra_select, order_by, group_by = self.pre_sql_setup(
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 85, in pre_sql_setup
    order_by = self.get_order_by()
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 487, in get_order_by
    raise DatabaseError(
django.db.utils.DatabaseError: ORDER BY term does not match any column in the result set.
```

Navigating to the Chant Search page and trying to search for a string causes a similar error. Some googling suggests this error is caused by trying to UNION two querysets (as we do on the Chant Search page, combining a queryset of Chants and one of Sequences) - django has changed how it handles this under the hood. This suggests that we may need to rework how we handle querysets on this page (and perhaps others).

We'll need to sort this out eventually, but I'm going to move on to other issues for the time being as this isn't urgent.


Discussion:
see #624 

Resolving patch:
diff --git a/django/cantusdb_project/main_app/views/chant.py b/django/cantusdb_project/main_app/views/chant.py
--- a/django/cantusdb_project/main_app/views/chant.py
+++ b/django/cantusdb_project/main_app/views/chant.py
@@ -831,7 +831,7 @@ def get_queryset(self) -> QuerySet:
                 else:
                     order = order_get_param
             else:
-                order = "siglum"
+                order = "source__siglum"
 
             # sort values: "asc" and "desc". Default is "asc"
             if sort_get_param and sort_get_param == "desc":


Test patch: