Skip to content

[BE] Return taxonomy type on the per-object tag endpoint #783

Closed
openedx/openedx-platform
#39259

Description

@thelmick-unicon

User Story

As a course author, I want the pages that show a content object's tags to be able to tell a competency apart from an ordinary tag, in order to be shown the right controls for each and not be offered actions that would damage competency configuration.

Acceptance Criteria

Scenario: A competency tag on a content object reports its taxonomy type
  Given a content object tagged from a competency taxonomy
  When that object's tags are requested
  Then each tag from that taxonomy reports a taxonomy type of competency

Scenario: An ordinary tag on a content object reports its taxonomy type
  Given a content object tagged from a taxonomy that is not a competency taxonomy
  When that object's tags are requested
  Then each tag from that taxonomy reports a taxonomy type that is not competency

Scenario: An object carrying both kinds reports each correctly
  Given a content object tagged from both a competency taxonomy and an ordinary one
  When that object's tags are requested
  Then the tags are distinguishable by their reported taxonomy type

Scenario: An object with no tags succeeds and reports nothing extra
  Given a content object with no tags
  When that object's tags are requested
  Then the response succeeds
    And it contains no taxonomy type information

Scenario: Reading tags for many objects does not slow down with the number of taxonomies
  Given several content objects tagged from several taxonomies
  When their tags are requested in one call
  Then the number of database queries does not grow with the number of taxonomies involved

Scenario: Existing consumers are unaffected
  Given a client reading the per-object tag endpoint that knows nothing of taxonomy type
  When it reads an object's tags
  Then every field it already relied on is unchanged

Description

This ticket's implementation belongs entirely in openedx-platform, not openedx-core. Per ADR 0013 (docs/openedx_tagging/decisions/0013-competency-taxonomy-detection.rst), nothing about "is this a competency taxonomy" may be added to openedx_tagging or the CBE app. #618 establishes this same boundary for the taxonomy endpoints: taxonomy_type is planned to live entirely in openedx-platform's TaxonomyOrgSerializer/TaxonomyOrgView (openedx/core/djangoapps/content_tagging/rest_api/v1/), subclassing openedx_tagging's generic base classes rather than adding anything to them. This ticket follows the same pattern for the equivalent per-object classes, ObjectTagOrgByTaxonomySerializer/ObjectTagOrgView, in that same openedx-platform app. Nothing here touches openedx_tagging's own ObjectTagsByTaxonomySerializer/ObjectTagView in openedx-core.

#618 is still in development, not merged. Checked directly against the live openedx-platform code, not assumed: taxonomy_type, get_taxonomy_type, and competencytaxonomy do not appear anywhere in the current serializers.py. So today, taxonomy type is not actually returned on the taxonomy endpoints yet either — this ticket depends on #618 landing first, not on an already-shipped precedent to extend.

The endpoint that returns the tags applied to a specific content object does not return taxonomy type, so the Course Outline page and the Libraries page cannot tell whether a tag on a subsection is a competency or an ordinary tag. That leaves those pages unable to hide the controls that must not be offered for competency tags. #784 is the frontend work that consumes this.

Technical Details

This section is background and a suggested approach, not the ticket's source of truth. The User Story and Acceptance Criteria define what must be true when the work is done.

In short

What this ticket does and does not decide. The rule for deciding whether a taxonomy is a competency taxonomy is #618's call to make, not this ticket's, and this ticket does not redecide it, reimplement it, or move it. Once #618 lands, this ticket follows its hasattr(taxonomy, "competencytaxonomy") check, applied to one more openedx-platform serializer, the one that returns a content object's tags.

Why the per-object endpoint is the one that matters. The Course Outline page and the Libraries page do not fetch the full taxonomy list to render a unit's tags. They fetch the tags applied to that object, and each tag arrives with its taxonomy identified but not typed. Without the type on that payload, the frontend would have to make a second request per taxonomy to decide whether to show a delete control, which is why #784 cannot be built until this lands.

Both pages read the same endpoint, confirmed against the frontend code. Course Outline's tag display and the Libraries pages' tag display both go through the same shared content-tags-drawer module in frontend-app-authoring: the same useContentTaxonomyTagsData() hook, calling the same api/content_tagging/v1/object_tags/{contentId}/ endpoint. There is one serializer to change, not two.

The performance shape to watch. A content object can carry tags from several taxonomies, and a Course Outline request covers many objects at once. Computing the type per tag by fetching its taxonomy would be an N+1 on one of the more heavily used authoring reads. The taxonomies involved must be fetched once for the whole response.

This is a purely additive change. The field is added; nothing existing is removed or renamed, so clients that do not know about it are unaffected.

Implementation specifics

  • Confirm [BE] Update Get endpoint to return Taxonomy Type. #618 has landed before starting. TaxonomyOrgSerializer.get_taxonomy_type() doesn't exist yet as of this writing; this ticket has nothing to reuse until it does.
  • Once [BE] Update Get endpoint to return Taxonomy Type. #618 lands, reuse its exact computation rather than duplicating the rule. TaxonomyOrgSerializer.get_taxonomy_type() (openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py) is planned to return "competency" if hasattr(obj, "competencytaxonomy"), "tags" otherwise. Call the same check, or extract it to a shared helper both serializers call, and say in the PR description which you did.
  • Add the field to ObjectTagOrgByTaxonomySerializer, in that same openedx-platform file, alongside TaxonomyOrgSerializer. This backs ObjectTagOrgView (views.py, same directory), which serves (api/content_tagging/v1/object_tags/{contentId}/, confirmed the single endpoint both Course Outline and Libraries read). Expose the field on each tag in the response, alongside the taxonomy identity already present.
  • Do not add anything to openedx_tagging's own ObjectTagsByTaxonomySerializer/ObjectTagView in openedx-core. ObjectTagOrgByTaxonomySerializer already subclasses it; this ticket only adds to the subclass, the same relationship [BE] Update Get endpoint to return Taxonomy Type. #618 establishes for the taxonomy endpoints.
  • Avoid the N+1. Use select_related on the tag's taxonomy (and its competencytaxonomy relation, mirroring [BE] Update Get endpoint to return Taxonomy Type. #618's planned TaxonomyOrgView.get_queryset() change) in ObjectTagOrgView's queryset so the taxonomies come back with the tags, and assert it with a query-count test rather than trusting inspection.
  • Do not change any other field, and do not change the endpoint's shape. Additive only.
  • Tests: a competency tag reports the competency type; an ordinary tag does not; an object carrying both is distinguishable; an untagged object succeeds; a query-count assertion over an object carrying tags from several taxonomies; a regression assertion that the previously existing fields are unchanged.
  • Out of scope: the frontend consumption ([FE] Hide tag removal and tag adding for competency tags on Course Outline #784), any change to the taxonomy endpoints ([BE] Update Get endpoint to return Taxonomy Type. #618’s own scope), and any change to how taxonomy type is decided.

Files to modify

File Nature of modification
openedx/core/djangoapps/content_tagging/rest_api/v1/serializers.py add taxonomy_type to ObjectTagOrgByTaxonomySerializer, reusing TaxonomyOrgSerializer's computation once #618 lands
openedx/core/djangoapps/content_tagging/rest_api/v1/views.py add select_related on the tag's taxonomy (and its competencytaxonomy relation) to ObjectTagOrgView's queryset, to avoid the N+1
the corresponding tests type-per-tag, mixed-object, empty, query-count, and additive-only regression tests

Context

Activity

  1. moved this from Needs additional details to Ready for Community Review in Competency Criteria and Student Progresson Sep 14, 2026
  2. thelmick-unicon commented on Sep 21, 2026

    @thelmick-unicon
    Author

    The discussion period for this ticket is now complete, and we appreciate all the feedback. We'll be moving forward with development based on the current ticket pending final Axim sign-off. That said, the conversation doesn't have to stop. If you still have feedback, please continue to add to this ticket. We'll review anything new and determine whether it fits within the current timeline or makes more sense as its own ticket for future work. Thanks again for helping make this better!

    @ormsbee This is ready for your final review. Thank you!

  3. moved this from Ready for Community Review to Final Axim Review in Competency Criteria and Student Progresson Sep 21, 2026
  4. ormsbee commented on Oct 6, 2026

    @ormsbee
    Contributor

    Approved, though I do hope we can move more of the taxonomy type awareness into core eventually.

  5. mgwozdz-unicon commented on Oct 6, 2026

    @mgwozdz-unicon
    Contributor

    @ormsbee Thanks! ADR 0013 calls this out as a known trade-off (

    **Known trade-off.** A future third taxonomy type needs another hardcoded branch in
    openedx-platform's shared serializer, the same cost a field-based approach would have
    avoided with a one-line enum addition. Accepted because keeping ``openedx_tagging`` free of
    any competency-specific reference, even an inert stored value, was judged more valuable
    than that extensibility, particularly given the project's move away from system-defined
    taxonomies, which makes a third taxonomy flavor unlikely soon.
    ), and Braden suggested a proper plugin API in core if we ever add another taxonomy type (#662 (comment)). If that happens, I think that's the right time to move the type detection out of platform and into openedx_tagging via that plugin API.

  6. moved this from In Progress to Unicon Code Review in Competency Criteria and Student Progresson Oct 19, 2026
  7. moved this from Unicon Code Review to Ready for Community Review in Competency Criteria and Student Progresson Nov 3, 2026
  8. moved this from Ready for Community Review to Community Code Review in Competency Criteria and Student Progresson Nov 3, 2026
  9. added a commit that references this issue on Nov 16, 2026
    449f6c4
  10. dvarenikqaconsultant commented on Nov 17, 2026

    @dvarenikqaconsultant

    Test report

    Environment: Master Sandbox (https://studio.master.openedx.io, https://apps.master.openedx.io)
    Implementation: openedx/openedx-platform#39259
    Test users: dmitryvarenikqa (staff), test670 (no role in the test course)
    Test type: API (GET and PUT /api/content_tagging/v1/object_tags/<object_id>/), plus a UI check of the tags panel on the Course Outline page, Postman
    Result: ✅ All scenarios passed, no bugs found

    Test data

    • Competency taxonomy "QA783 Competencies" (tags "QA783 Comp A", "QA783 Comp B"), imported from JSON with the Competency type.
    • Ordinary taxonomy "QA783 Ordinary Tags" (tags "QA783 Tag X", "QA783 Tag Y"), imported from CSV with the Tags type.
    • Temporary ordinary taxonomy "QA783 Temp", which was deleted during the run.
    • Course course-v1:QA783+TAGS+2026 with five subsections, each tagged differently (see the table below).
    • Content library lib:QA783:lib783 with one Text component tagged "QA783 Comp A".

    Acceptance criteria

    Scenario Object Expected Actual Result
    A competency tag reports its taxonomy type Subsection with "QA783 Comp A" only The competency taxonomy's entry has taxonomy_type: "competency" 200, taxonomy_type: "competency" ✅ Pass
    An ordinary tag reports its taxonomy type Subsection with "QA783 Tag X" only The ordinary taxonomy's entry has a type that is not competency 200, taxonomy_type: "tags" ✅ Pass
    An object carrying both kinds reports each correctly Subsection with two competency tags and two ordinary tags The two kinds are distinguishable by their type 200, two taxonomy entries: "QA783 Competencies" is competency, "QA783 Ordinary Tags" is tags, each with both of its tags ✅ Pass
    An object with no tags succeeds and reports nothing extra Subsection with no tags Success, no taxonomy type information 200, body is {"<object_id>": {"taxonomies": []}}, no taxonomy_type anywhere ✅ Pass
    Reading tags does not slow down with the number of taxonomies n/a The number of database queries does not grow with the number of taxonomies Database query counts are not observable on Master Sandbox. This scenario is covered by the query-count test in the PR Covered by automated test
    Existing consumers are unaffected Subsection with both kinds of tags Every previously existing field is unchanged Each taxonomy entry still has name, taxonomy_id, can_tag_object, export_id and tags, with taxonomy_type added. Each tag still has value, lineage, can_delete_objecttag and is_copied, with no new fields. The tags panel on the Course Outline page shows the subsection's 4 tags grouped under both taxonomies, as before ✅ Pass

    Additionally tested

    Check Expected Actual Result
    GET with the ?taxonomy=<competency taxonomy id> filter on the subsection with both kinds of tags One taxonomy entry, competency type 200, one entry, competency ✅ Pass
    Content library component tagged with "QA783 Comp A" Competency type, same as for a course subsection 200, competency ✅ Pass
    Subsection tagged from "QA783 Temp", after that taxonomy was deleted The request still succeeds 200, no server error ✅ Pass
    test670, who has no role in the course, requests the subsection's tags Access denied as before, no type information leaked 403 "You do not have permission to view object tags for this taxonomy or object_id.", no taxonomy_type in the body ✅ Pass
    PUT re-applying "QA783 Comp A" to the competency-only subsection The response carries the type too 200, competency, tags unchanged ✅ Pass
    Competency taxonomy reassigned from all organizations to the single organization QA783 The type does not depend on organization assignment 200, competency ✅ Pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions