Fix #113: Fix badge names returning null in profile endpoint #129
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "typosaurus/ticket-113"
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?
Resolves #113.
Plan
Implementation Plan: Fix Null Badge Names in Profile JSON Response
1. Code Change – Add Pydantic Alias to
BadgeOut.nameFile:
devplacepy/schemas/content.pyfrom pydantic import Fieldis present at the top of the file (it is already imported elsewhere in the module, but confirm the import is available. If not, add it.)This alias tells Pydantic to accept the key
badge_namefrom the input dict (the raw database row) and serialize it asnamein the JSON output. HTML rendering is unaffected because it readsbadge['badge_name']directly from the raw dict before Pydantic processing.2. Verify No Existing
BadgeOutConstructions Usename=Keyword ArgumentSearch the entire codebase for all occurrences of
BadgeOut(.If any call site passes
name=as a keyword argument (e.g.,BadgeOut(name="something")), the alias will reject that input unless the model config includespopulate_by_name=True.badge_name=instead, ormodel_config = ConfigDict(populate_by_name=True)to theBadgeOutclass (or its parent_Out).Given the investigation flow (data comes from database dicts, not programmatic construction), it is expected no such keyword constructions exist. However, this must be confirmed.
3. Add a JSON‑Serialization Test for Badge Names
New test location:
tests/api/profile.py(or a dedicated schema test, e.g.tests/unit/schemas/test_badge_out.py).The test must:
TestClientto send a GET request to the profile endpoint withAccept: application/json.badges[]has a non‑nullnamethat matches the expected badge text for the test user’s badges.If the test database does not guarantee a badge for the test user, either:
badgesis non‑empty, allnamefields are non‑null.Existing test pattern: Look at
tests/api/streaks.py:130for how API tests are structured.4. Run Verification Commands
Execute the project’s test command as specified:
Initially, run only the modified/new tests to confirm they pass, then run the full suite to ensure no regressions. If any unrelated failures appear (e.g. those seen in earlier attempts), verify they predate this change (should match baseline).
No lint command is explicitly required, but if a lint step is part of CI, ensure the change introduces no lint violations (e.g. unused imports, formatting). Run
make lintor equivalent if available.Definition of Done
BadgeOut.namefield indevplacepy/schemas/content.pyhas an alias"badge_name".BadgeOut(name=...)constructions; if found, either those sites have been updated orpopulate_by_name=Truehas been added to the model config.Accept: application/jsonand asserts that every badge in the response has a non‑nullname.python -m pytestas specified) passes with no new failures.Opened automatically by Typosaurus.
Checkout
From your project repository, check out a new branch and test the changes.