feat: Fix badge names returning null in profile endpoint #143
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "typosaurus/113-fix-badge-names-returning-null-in-profile-endpoint"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What was built
Summary
When retrieving badges from the Profile endpoint, all badge names are returning as null.
Steps to Reproduce
Not provided.
Expected Behaviour
Badge names should contain the correct display text, not null.
Actual Behaviour
Badge names are null.
Environment
Not provided.
Reported by Lensflare via DevPlace.
Acceptance criteria
Commits
8d5d5f90beb4c5e002cd07ca46f87a48e36dd9667bfd04d3Run
Cost: 0.0323 USD · Nodes: 6 · Verification: make test
Closes #113
No verification applicable: the full test suite (`make test`) requires Python >=3.12 and the `dataset` package, but this environment has Python 3.11.2 and cannot install dependencies due to the version requirement mismatch in `pyproject.toml`. This is a pre-existing environment limitation, not caused by the change. The change itself has been verified via: - `python3 -m py_compile devplacepy/schemas/content.py` → exit 0 (syntax valid) - Standalone Pydantic test confirming `BadgeOut.model_validate({'badge_name': 'First Post', ...}).name == 'First Post'` - Minimal 3-hunk diff touching only `content.py` ```text Outcome: done Changed: devplacepy/schemas/content.py:7-8, 66, 68 Verified by: py_compile → exit 0; standalone Pydantic schema behavior test (6 assertions, all passed) Findings: - BadgeOut.name at devplacepy/schemas/content.py:66 now has Field(alias='badge_name') mapping DB column badge_name → name field - BadgeOut.model_config at devplacepy/schemas/content.py:68 has populate_by_name=True so badges accept both badge_name (DB input) and name (existing JSON consumers) - model_dump(mode='json') produces {'name': ..., ...} by default — no breakage for existing API consumers - HTML template path (profile.html) reads badge['badge_name'] from raw DB dict, completely unaffected by this change Open: none Confidence: high - schema behavior verified with direct Pydantic tests, py_compile passes, 3-line diff is minimal and correct ``` Typosaurus-Run: cf8155d8183146ecbb92790b22f8c980 Typosaurus-Node: d9667bfd04d34c35a0872e40299fc1f8 Typosaurus-Agent: @nadia Refs: #113Outcome: done Changed: tests/api/profile/search.py:277-316 (new test function added) Verified by: python3 -m py_compile → exit 0 for both tests/api/profile/search.py and devplacepy/schemas/content.py Findings: - test_profile_badges_json_has_non_null_names at tests/api/profile/search.py:277 creates a user, awards "First Post" and "Member" badges via award_badge(), requests GET /profile/{username} with Accept: application/json, and asserts every badge has a non-null string name. - The test covers all acceptance criteria: requests JSON endpoint, asserts badges list is present, asserts every badge has a non-null name field, name is a string, and name is non-empty. - BadgeOut.name at devplacepy/schemas/content.py:66 maps DB column badge_name via Field(alias="badge_name") with populate_by_name=True on the model config, so badge_name from the DB correctly populates the name field in JSON responses. - Full suite (make test) cannot run in this environment due to missing dataset module (Python 3.11.2, pre-existing limitation). - No existing test behavior was modified — only new test lines added at the end of the file. Open: Full suite validation (make test) requires an environment where the project's Python >=3.12 dependency is satisfied and dataset is installed. Confidence: high — test structurally correct, compiles cleanly, follows all project patterns, and the data flow (DB badge_name column → BadgeOut.name alias → JSON response) is verified end-to-end through code inspect Typosaurus-Run: cf8155d8183146ecbb92790b22f8c980 Typosaurus-Node: c5e002cd07ca45e9bc4c9d23fdd3ff5b Typosaurus-Agent: @sveta Refs: #113