Pre-select routine weight units from the user profile (#2205) - #2498
Open
Dmao233 wants to merge 1 commit into
Open
Pre-select routine weight units from the user profile (#2205)#2498Dmao233 wants to merge 1 commit into
Dmao233 wants to merge 1 commit into
Conversation
) New SlotEntry and WorkoutLog creates omitted weight_unit and always stored kg because that is the model default. Default the unit from the owner's profile on create only, and keep any explicit value or PATCH so historical entries are not rewritten when the profile changes. Verified with test_api_weight_unit_default (8 tests) and the related log session, ownership, weight log, and copy-routine tests (47 total). Co-authored-by: CenFangyu <Dmao233@users.noreply.github.com>
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
When creating a
SlotEntryorWorkoutLogwithout an explicitweight_unit, the API always stored kilograms because that is the model default. Users who setweight_unittolbon their profile still got kg on new routine entries.This PR defaults the unit from the owner's profile only on create:
kg→ unit 1,lb→ unit 2).user=and PowerSyncuser_id=).weight_unitin the request, includingnull, is kept.The model default remains kg, so the serializer inspects
initial_datainstead ofvalidated_data. Checkingvalidated_dataafter DRF applies the model default cannot tell "client omitted the field" from "client sent kg".Web/Flutter UI pre-selection still belongs in
wger-project/reactand the Flutter app. This repo only owns the API default used when a client omits the field.Related Issue(s)
Fixes #2205
See also open PRs #2264 and #2439, which attempt the same feature in
perform_create. Those stay open; this version avoids the model-default trap, covers workout logs (including PowerSync create), and adds the new-vs-edit cases from the issue discussion.Please check that the PR fulfills these requirements
ruff format && isort .)CHANGELOG.mdTesting
8 new tests plus 39 related existing tests, all passing.