Skip to content

Commit f522df0

Browse files
feat!: remove deprecated "descendant_count" completely
1 parent a563fae commit f522df0

5 files changed

Lines changed: 18 additions & 28 deletions

File tree

src/openedx_tagging/data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class TagData(TypedDict):
2121
value: str
2222
external_id: str | None
2323
child_count: int
24-
descendant_count: int # Deprecated; do not use.
2524
depth: int
2625
parent_value: str | None
2726
# Note: usage_count may or may not be present, depending on the request.

src/openedx_tagging/models/base.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ def _get_filtered_tags_free_text(
492492
qs = qs.annotate(
493493
depth=Value(0),
494494
child_count=Value(0),
495-
descendant_count=Value(0),
496495
external_id=Value(None, output_field=models.CharField()),
497496
parent_value=Value(None, output_field=models.CharField()),
498497
_id=Value(None, output_field=models.CharField()),
@@ -524,13 +523,11 @@ def _get_filtered_tags_one_level(
524523
qs = self.tag_set.filter(parent=None)
525524
qs = qs.annotate(parent_value=Value(None, output_field=models.CharField()))
526525
qs = qs.annotate(child_count=models.Count("children", distinct=True)) # type: ignore[no-redef]
527-
# Add the deprecated "descendant_count field". For now it's just the same as child_count.
528-
qs = qs.annotate(descendant_count=F("child_count"))
529526
# Filter by search term:
530527
if search_term:
531528
qs = qs.filter(value__icontains=search_term)
532529
qs = qs.annotate(_id=F("id")) # ID has an underscore to encourage use of 'value' rather than this internal ID
533-
qs = qs.values("value", "child_count", "descendant_count", "depth", "parent_value", "external_id", "_id")
530+
qs = qs.values("value", "child_count", "depth", "parent_value", "external_id", "_id")
534531
qs = qs.order_by("value")
535532
if include_counts:
536533
# We need to include the count of how many times this tag is used to tag objects.
@@ -606,14 +603,12 @@ def _get_filtered_tags_deep(
606603
.annotate(count=models.Func(F("id"), function="Count"))
607604
)
608605
qs = initial_qs.annotate(child_count=models.Subquery(child_count_sq.values("count")))
609-
# Add the deprecated "descendant_count" field. For now it just is the same as child_count.
610-
qs = qs.annotate(descendant_count=F("child_count"))
611606

612607
# Add the parent value
613608
qs = qs.annotate(parent_value=F("parent__value"))
614609
qs = qs.annotate(_id=F("id")) # ID has an underscore to encourage use of 'value' rather than this internal ID
615610
qs = qs.values( # type: ignore[assignment]
616-
"value", "child_count", "descendant_count", "depth", "parent_value", "external_id", "_id"
611+
"value", "child_count", "depth", "parent_value", "external_id", "_id"
617612
)
618613
# lineage is a case-insensitive column storing "Root\tParent\t...\tThisValue\t", so
619614
# ordering by it gives the tree sort order that we want.

src/openedx_tagging/rest_api/v1/serializers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ class TagDataSerializer(UserPermissionsSerializerMixin, serializers.Serializer):
226226
value = serializers.CharField()
227227
external_id = serializers.CharField(allow_null=True)
228228
child_count = serializers.IntegerField()
229-
descendant_count = serializers.IntegerField() # deprecated
230229
depth = serializers.IntegerField()
231230
parent_value = serializers.CharField(allow_null=True)
232231
usage_count = serializers.IntegerField(required=False)

tests/openedx_tagging/test_models.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ def test_get_root(self) -> None:
329329
del r["_id"] # Remove the internal database IDs; they aren't interesting here and a other tests check them
330330
assert result == [
331331
# These are the root tags, in alphabetical order:
332-
{"value": "Archaea", "child_count": 3, "descendant_count": 3, **common_fields},
333-
{"value": "Bacteria", "child_count": 2, "descendant_count": 2, **common_fields},
334-
{"value": "Eukaryota", "child_count": 5, "descendant_count": 5, **common_fields},
332+
{"value": "Archaea", "child_count": 3, **common_fields},
333+
{"value": "Bacteria", "child_count": 2, **common_fields},
334+
{"value": "Eukaryota", "child_count": 5, **common_fields},
335335
]
336336

337337
def test_get_child_tags_one_level(self) -> None:
@@ -345,11 +345,11 @@ def test_get_child_tags_one_level(self) -> None:
345345
del r["_id"] # Remove the internal database IDs; they aren't interesting here and a other tests check them
346346
assert result == [
347347
# These are the Eukaryota tags, in alphabetical order:
348-
{"value": "Animalia", "child_count": 7, "descendant_count": 7, **common_fields},
349-
{"value": "Fungi", "child_count": 0, "descendant_count": 0, **common_fields},
350-
{"value": "Monera", "child_count": 0, "descendant_count": 0, **common_fields},
351-
{"value": "Plantae", "child_count": 0, "descendant_count": 0, **common_fields},
352-
{"value": "Protista", "child_count": 0, "descendant_count": 0, **common_fields},
348+
{"value": "Animalia", "child_count": 7, **common_fields},
349+
{"value": "Fungi", "child_count": 0, **common_fields},
350+
{"value": "Monera", "child_count": 0, **common_fields},
351+
{"value": "Plantae", "child_count": 0, **common_fields},
352+
{"value": "Protista", "child_count": 0, **common_fields},
353353
]
354354

355355
def test_get_grandchild_tags_one_level(self) -> None:
@@ -363,13 +363,13 @@ def test_get_grandchild_tags_one_level(self) -> None:
363363
del r["_id"] # Remove the internal database IDs; they aren't interesting here and a other tests check them
364364
assert result == [
365365
# These are the Eukaryota tags, in alphabetical order:
366-
{"value": "Arthropoda", "child_count": 0, "descendant_count": 0, **common_fields},
367-
{"value": "Chordata", "child_count": 1, "descendant_count": 1, **common_fields},
368-
{"value": "Cnidaria", "child_count": 0, "descendant_count": 0, **common_fields},
369-
{"value": "Ctenophora", "child_count": 0, "descendant_count": 0, **common_fields},
370-
{"value": "Gastrotrich", "child_count": 0, "descendant_count": 0, **common_fields},
371-
{"value": "Placozoa", "child_count": 0, "descendant_count": 0, **common_fields},
372-
{"value": "Porifera", "child_count": 0, "descendant_count": 0, **common_fields},
366+
{"value": "Arthropoda", "child_count": 0, **common_fields},
367+
{"value": "Chordata", "child_count": 1, **common_fields},
368+
{"value": "Cnidaria", "child_count": 0, **common_fields},
369+
{"value": "Ctenophora", "child_count": 0, **common_fields},
370+
{"value": "Gastrotrich", "child_count": 0, **common_fields},
371+
{"value": "Placozoa", "child_count": 0, **common_fields},
372+
{"value": "Porifera", "child_count": 0, **common_fields},
373373
]
374374

375375
def test_get_depth_1_search_term(self) -> None:
@@ -381,7 +381,6 @@ def test_get_depth_1_search_term(self) -> None:
381381
{
382382
"value": "Archaea",
383383
"child_count": 3,
384-
"descendant_count": 3,
385384
"depth": 0,
386385
"usage_count": 0,
387386
"parent_value": None,
@@ -400,7 +399,6 @@ def test_get_depth_1_child_search_term(self) -> None:
400399
{
401400
"value": "Archaebacteria",
402401
"child_count": 0,
403-
"descendant_count": 0,
404402
"depth": 1,
405403
"parent_value": "Bacteria",
406404
"external_id": None,
@@ -511,7 +509,6 @@ def test_tags_deep(self) -> None:
511509
"depth": 3,
512510
"usage_count": 0,
513511
"child_count": 0,
514-
"descendant_count": 0,
515512
"external_id": None,
516513
"_id": 21, # These IDs are hard-coded in the test fixture file
517514
}

tests/openedx_tagging/test_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ def test_large_taxonomy(self):
16141614
self.client.force_authenticate(user=self.staff)
16151615

16161616
url = self.large_taxonomy_url + "?include_counts"
1617-
with self.assertNumQueries(1):
1617+
with self.assertNumQueries(3):
16181618
response = self.client.get(url)
16191619

16201620
assert response.status_code == status.HTTP_200_OK

0 commit comments

Comments
 (0)