Skip to content

fix(b2b): return blank learner names as null - #71

Merged
daniellefrappier18 merged 2 commits into
mainfrom
daniellef/null-blank-learner-names
Sep 28, 2026
Merged

daniellefrappier18 merged 2 commits into
mainfrom
daniellef/null-blank-learner-names

Conversation

@daniellefrappier18

@daniellefrappier18 daniellefrappier18 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

Follow-up to mitodl/mit-learn#3958

Description (What does it do?)

Return blank learner names as null so they sort after real names, not before them.

On the contract learner directory, rows with no learner name all land on page 1. The learner-progress sort is full_name IS NULL, full_name ASC. An empty or whitespace-only full_name is not NULL, so it sorts ahead of every real name.

  • Select NULLIF(TRIM(full_name), '') AS full_name in the learner-progress records query, so the existing nulls-last sort covers blank names too
  • Apply the same normalization in the learner-records enrollments and learners queries, including the recomputed rollup's MAX() and its COALESCE(l.full_name, e.full_name). Otherwise a blank name on one side could hide a real name on the other.
Implementation details
  • Each tenant module gets its own _BLANK_AS_NULL_NAME constant, matching how both modules already keep their own copy of _COMPLETION_STATUS.
  • Search still works. It runs in the outer select over the normalized column, and a blank name never matched a search term anyway.
  • The frontend handles blank names on its own in the companion PR, fix(b2b): show learner email and icon avatar when name is blank mit-learn#3992. This change only fixes the ordering.

Before:
Learner's with blank name were sorted to the top:
Screenshot 2026-09-25 at 9 50 11 AM

How can this be tested?

  • uv run pytest: all 287 tests pass, including new SQL assertions for learner-progress and for the enrollments, learners, learners?contract_id=, and learners?include_inactive=true paths.
  • uv run ruff check src tests passes.
  • Against real data: call GET /organizations/<org>/contracts/<contract>/learner-progress?sort=full_name for a contract whose learners include blank names. Rows without a name come back with full_name: null on the last page, not at the top of page 1.

🤖 Generated with Claude Code

Upstream stores "" rather than NULL for learners without a profile name.
Those rows sorted ahead of every real name and clumped on page 1 of the
contract learner directory. Normalize with NULLIF(TRIM(full_name), '')
in the learner-progress and learner-records queries so they sort last
with the other missing names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@daniellefrappier18
daniellefrappier18 merged commit e49e884 into main Sep 28, 2026
5 checks passed
@daniellefrappier18
daniellefrappier18 deleted the daniellef/null-blank-learner-names branch September 28, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants