Repository navigation
Conversation
…ory is missing The React calendar reads body weight through `getBodyWeightCategory`, which threw "No official body weight category found" on an empty response. The calendar gates its whole detail panel behind `isSuccess` of every query, so that throw left the panel stuck on its loading spinner even though the workout, measurement and nutrition reads all succeeded. The official body weight category is created lazily (a `@disable_for_loaddata` post_save signal, the profile, the legacy weight endpoint, the CSV import), so it is not guaranteed to exist: accounts loaded from a fixture -- most notably the default `admin` account shipped with the server -- start without one and hit this on first visit to the calendar. Treat a missing category as "no body weight recorded yet" instead of an error: - getBodyWeightCategory resolves `null` on an empty response (null, not undefined, since it resolves a react-query query). A real request failure still rejects through axios. - useBodyWeightQuery returns an empty history when there is no category, so its consumers (calendar, dashboard card, BMI calculator, weight chart) read as empty rather than failing. - The body weight screen renders its empty state (the add-weight FAB creates the category) instead of dereferencing a null category. Adds coverage: the api resolves null on empty, the query yields an empty history without fetching entries, and the calendar renders its detail panel when the category is missing.
hirak214
force-pushed
the
fix/calendar-missing-bodyweight-category
branch
from
September 19, 2026 09:51
ee96292 to
c379620
Compare
rolandgeider
added a commit
to wger-project/wger
that referenced
this pull request
Sep 26, 2026
Member
|
Hi and thanks for the PR! You are right that it's possible to create users without this category, but I think this is the wrong place to handle this case (we would need special code for the flutter app as well, etc.). I have fixed the bootstrap command so that we can be sure this doesn't happen and can continue to assume the category always exists |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
getBodyWeightCategoryresolvesnullon an empty response instead of throwing (null, notundefined, since it resolves a react-query query). A genuine request failure still rejects through axios.useBodyWeightQueryreturns an empty history when there is no official body weight category, so its consumers (calendar, dashboard weight card, BMI calculator, plan weight chart) read as empty rather than failing.Related Issue(s)
Please check that the PR fulfills these requirements
Bug
Opening the Calendar leaves the day-detail panel stuck on its loading spinner forever, even though the workout, measurement and nutrition data all load fine.
getBodyWeightCategory(api/bodyWeight.ts) throwsNo official body weight category foundwhen the category query is empty.CalendarComponentgates its whole detail panel behindisSuccessof every query, so that throw keeps the panel from ever rendering.Why the category can be missing
The comment there assumes "The server guarantees that every user has exactly one", but the server creates it lazily and the creating
post_savesignal is@disable_for_loaddata— so users loaded from a fixture never get one. The most common case is the defaultadminaccount shipped with the server: log in as it and open the calendar before recording a weight, and you hit the spinner. Imported users and deleted categories land in the same state.Tests
api/bodyWeight.test.ts— empty response resolves tonull, not a throw.queries/bodyWeight.test.tsx— a missing category yields an empty history and does not fetch entries.CalendarComponent.test.tsx— the detail panel still renders when the category is missing.npm run typecheckandnpm run lintare clean; the touched suites pass.Reproduce
Fresh server, log in as the default
admin(or any fixture-created user that never recorded a body weight), open the Calendar → detail panel spins forever. With this change it renders normally.