Skip to content

Handle defaultMeasureId 0 when creating and editing custom foods - #4

Merged
ColinToft merged 2 commits into
mainfrom
colin/default-measure-zero
Oct 13, 2026
Merged

ColinToft merged 2 commits into
mainfrom
colin/default-measure-zero

Conversation

@ColinToft

Copy link
Copy Markdown
Owner

Regression from #3: Cronometer stores a custom food whose only measure is `g` (1 g) with `defaultMeasureId: 0` (verified live). `add_custom_food(serving_name="g", serving_grams=1)` then failed with "has no measure 0 after saving" even though the food was created, and `update_custom_food` refused such foods.

  • `create_custom_food` uses the food's one measure (exactly one required) instead of `defaultMeasureId`.
  • `_default_measure` treats id 0 as "no explicit default": the sole measure is returned; several measures raise. A non-zero id that matches nothing still raises.
  • `create_recipe` finds its serving as the one non-fixed measure (as `update_recipe` does). Trusting `defaultMeasureId` there could rename `g` or a virtual id-0 "full recipe" measure if the default ever moved or read back as 0.
  • Left alone: diary enrichment (falls back to the default only when the entry's `measureId` is unknown, and 0 yields no serving info rather than a wrong one) and `_gram_measure_id` (already maps a missing default to 0, and gram foods match the `g` measure first).

FakeFoodServer now keeps `defaultMeasureId` 0 for a lone `g` measure. 562 tests pass; 5 mutations of the new branches are all caught. Live: created, renamed and retired a throwaway `g`/1 g food.

🤖 Generated with Claude Code

ColinToft and others added 2 commits October 13, 2026 09:51
Cronometer stores a custom food whose only measure is "g" (1 g) with
defaultMeasureId 0, so add_custom_food(serving_name="g", serving_grams=1)
failed after creating the food, and update_custom_food refused it.

- create_custom_food takes the food's one measure instead of the default.
- _default_measure treats id 0 as "no explicit default": the sole measure
  is the default; several measures are refused as ambiguous.
- create_recipe identifies its serving as the one non-fixed measure, as
  update_recipe already does, instead of trusting defaultMeasureId.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only resolve the default measure when the serving or per-serving nutrients
change; a rename never touches it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant