Signbank / Global-signbank

An online sign dictionary and sign database management system for research purposes. Developed originally by Steve Cassidy/ This repo is a fork for the Dutch version, previously called 'NGT-Signbank'.
http://signbank.cls.ru.nl
BSD 3-Clause "New" or "Revised" License
19 stars 12 forks source link

Bug in Django Sign Language query [CODE] #1313

Open susanodd opened 2 months ago

susanodd commented 2 months ago

This query finds no datasets for the sign language

https://github.com/Signbank/Global-signbank/blob/c11e21db589f0bf34582d07c05da3c9a9d4ea7e0/signbank/dictionary/views.py#L2463-L2474

It is used in the template at datasets/unassigned_glosses

The related model reference "dataset_set" does not find anything.

vanlummelhuizen commented 2 months ago

@susanodd I cannot see what the problem is. I ran the code in a Django shell and it seems fine:

>>> from django.db.models import OuterRef, Subquery, Count, Prefetch
>>> unassigned_glosses = Gloss.objects.filter(
...             lemma__dataset=None,
...             signlanguage=OuterRef('pk')
...         ).order_by().values('signlanguage')
>>> count_unassigned_glosses = unassigned_glosses.annotate(cnt=Count('pk')).values('cnt')
>>> signlanguages = SignLanguage.objects.prefetch_related(
...     Prefetch(
...         'dataset_set',
...         queryset=Dataset.objects.all(),
...         to_attr='datasets'
...     )
... ).annotate(
...     num_unassigned_glosses=Subquery(
...         count_unassigned_glosses,
...         output_field=models.IntegerField()
...     )
... )
>>> signlanguages
<QuerySet [<SignLanguage: ASL>, <SignLanguage: AdaSL>, <SignLanguage: BISINDO>, <SignLanguage: Berbey SL>, <SignLanguage: CSL>, <SignLanguage: Catalan Sign Languag>, <SignLanguage: David Rose Signs>, <SignLanguage: EmblemsNL>, <SignLanguage: IS>, <SignLanguage: ISL>, <SignLanguage: JSL>, <SignLanguage: Kata Kolok>, <SignLanguage: Konchri Sain>, <SignLanguage: Korean Sign Language>, <SignLanguage: LSFB>, <SignLanguage: LaSiMa>, <SignLanguage: NGT>, <SignLanguage: NTS>, <SignLanguage: Sign Languages of CA>, <SignLanguage: TSL>, '...(remaining elements truncated)...']>
>>> signlanguages.count()
22

The page https://signbank.cls.ru.nl/datasets/unassigned_glosses also seems to work fine.

susanodd commented 2 months ago

Yes, the code works without bugs, but the column on the right ought to show a selection of datasets that use the sign language. (It's supposed to be the 'dataset_set' but it is empty. It should show "datasets for this sign language" in the menu.

vanlummelhuizen commented 2 months ago

@susanodd I see what you mean now.

The problem is in this bit:

https://github.com/Signbank/Global-signbank/blob/41be3211a5e4c8618fa03eee1479628474a10b8e/signbank/dictionary/templates/dictionary/unassigned_glosses.html#L70-L79

Because of the first line, if there are no unassigned glosses, it will go to the else and display "No datasets for this sign language".

A possible patch:

diff --git a/signbank/dictionary/templates/dictionary/unassigned_glosses.html b/signbank/dictionary/templates/dictionary/unassigned_glosses.html
index f1224837..42671971 100644
--- a/signbank/dictionary/templates/dictionary/unassigned_glosses.html
+++ b/signbank/dictionary/templates/dictionary/unassigned_glosses.html
@@ -74,6 +74,8 @@
                 <option value="{{ dataset.id }}">{{ dataset.name }}</option>
                 {% endfor %}
                 </select>
+                {% elif not signlanguage.num_unassigned_glosses %}
+                {% trans "No glosses to assign" %}
                 {% else %}
                 {% trans "No datasets for this sign language" %}
                 {% endif %}