Skip to content

Normalise node id in public contentnode tree endpoint - #6464

Open
ManyaJain111 wants to merge 1 commit into
learningequality:hotfixesfrom
ManyaJain111:fix-contentnode-tree-uppercase-id
Open

ManyaJain111 wants to merge 1 commit into
learningequality:hotfixesfrom
ManyaJain111:fix-contentnode-tree-uppercase-id

Conversation

@ManyaJain111

Copy link
Copy Markdown

Summary

The public contentnode tree endpoint now returns the same response for a node id in uppercase as in lowercase. Before this change, an uppercase id returned the parent node with no children.

ContentNodeTreeViewset.retrieve validated pk with UUID(pk) but it discarded the result and it kept using pk exactly as sent. The database lookups would still findd the node, because Postgres compares UUIDs as values and ignores case. But when building the nested response, children are attached to the parent by a plain string comparison:

if desc["parent"] == pk:

desc["parent"] is serialized as lowercase hex, so for an uppercase pk this never matched, and every child was silently dropped.

Approach: keep the parsed value instead of discarding it:

pk = UUID(pk).hex

.hex always gives 32 lowercase characters with no dashes, the same form the serialized parent values use. Everything after validation, including the queries and the comparison, now works with one canonical id. This is the normalisation the issue asks for, and it's a one-line change at the point where the id is already being parsed. Invalid ids still return 400 as before.

References

Fixes #6417

Reviewer guidance

Automated tests: I added test_contentnode_tree_uppercase_id to contentcuration/kolibri_public/tests/test_content_app.py. It requests the same node with its id in lowercase and in uppercase, and checks that the uppercase request returns 200, includes children, and matches the lowercase response. It fails without the fix ('children' not found) and passes with it. All tests in the file pass, and no existing tests were changed.

pytest contentcuration/kolibri_public/tests/test_content_app.py

Manual verification: on the dev server, using the id of a topic node that has children:

  • GET /api/public/v2/contentnode_tree/<id>/ returned the node with children
  • GET /api/public/v2/contentnode_tree/<ID IN UPPERCASE>/ returned the same response, also with children (before the fix, children was missing)

Note for reviewers: because the fix uses UUID(pk).hex, ids sent in dashed form (xxxxxxxx-xxxx-…) are normalised too. They had the same mismatch before.

No UI changes.

AI usage

I used Claude Code to first write a regression test that reproduced the missing children issue. I then guided it to trace the failure to the exact location in the code, investigated the root cause, and worked with it to implement a targeted fix. Finally, I reviewed the changes and independently re-ran the tests to verify that the issue was resolved.

I reviewed the changes and tests line by line, made sure I understood why pk needed to be normalised before the string comparison, and independently re-ran the tests on a branch based on hotfixes.

@ManyaJain111
ManyaJain111 requested review from a team and leq-bot November 21, 2026 20:41
@learning-equality-bot learning-equality-bot Bot linked an issue Nov 21, 2026 that may be closed by this pull request
2 tasks
@learning-equality-bot

Copy link
Copy Markdown
Contributor

👋 Hi @ManyaJain111, thanks for contributing!

For the review process to begin, please verify that the following is satisfied:

  • Contribution is aligned with our contributing guidelines

  • Pull request description has correctly filled AI usage section & follows our AI guidance:

    AI guidance

    State explicitly whether you didn't use or used AI & how.

    If you used it, ensure that the PR is aligned with Using AI as well as our DEEP framework. DEEP asks you:

    • Disclose — Be open about when you've used AI for support.
    • Engage critically — Question what is generated. Review code for correctness and unnecessary complexity.
    • Edit — Review and refine AI output. Remove unnecessary code and verify it still works after your edits.
    • Process sharing — Explain how you used the AI so others can learn.

    Examples of good disclosures:

    "I used Claude Code to implement the component, prompting it to follow the pattern in ComponentX. I reviewed the generated code, removed unnecessary error handling, and verified the tests pass."

    "I brainstormed the approach with Gemini, then had it write failing tests for the feature. After reviewing the tests, I used Claude Code to generate the implementation. I refactored the output to reduce verbosity and ran the full test suite."

📢✨ Before we assign a reviewer:

  • @rtibblesbot will pre-review this pull request. Its comments are generated by an LLM, and should be evaluated accordingly.
  • We'll also invite community pre-review. See the community review guidance for both authors and reviewers.

Also check that issue requirements are satisfied & you ran pre-commit locally.

Pull requests that don't follow the guidelines will be closed.

Reviewer assignment can take up to 2 weeks.

rtibblesbot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Waiting for changes

Outcome: reviewed a38ffd4

Last updated: 2026-11-21 20:50 UTC

@rtibblesbot rtibblesbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #6464 fixes the uppercase node id bug at its root. The id is normalised where it is parsed. The parent comparison and tree queries now see one canonical form. The regression test pins the full response against the lowercase request. CI is passing.

Next step: Needs a full code review by a human engineer.

  • The author is outside the team.

Written by rtibblesbot, an LLM-based coding agent.


try:
UUID(pk)
pk = UUID(pk).hex

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: UUID(pk).hex matches the serializer's parent form. The parent check and tree queries now share one canonical id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Public contentnode tree returns no children for an uppercase node id

2 participants