[PR #414] [MERGED] Fix: Spool Empty Weight Catalog Matching by ID #1033

Closed
opened 2026-05-06 12:34:36 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/maziggy/bambuddy/pull/414
Author: @Keybored02
Created: 2/17/2026
Status: Merged
Merged: 2/18/2026
Merged by: @maziggy

Base: 0.2.1bHead: feature/filament-fix


📝 Commits (6)

  • 233f50c fix(inventory): spool catalog entry ID matching
  • e17b55f Add tests for core_weight_catalog_id handling
  • b0d341a Merge branch '0.2.1b' into feature/filament-fix
  • 87c6bfe fix(spool-form): improve handling of core_weight_catalog_id and catalog ID selection logic
  • a649a24 Merge branch 'feature/filament-fix' of https://github.com/Keybored02/bambuddy into feature/filament-fix
  • 72f5bd4 Merge branch '0.2.1b' into feature/filament-fix

📊 Changes

8 files changed (+206 additions, -9 deletions)

View changed files

📝 backend/app/core/database.py (+6 -0)
📝 backend/app/models/spool.py (+3 -0)
📝 backend/app/schemas/spool.py (+2 -0)
📝 frontend/src/__tests__/components/SpoolFormModal.test.tsx (+135 -0)
📝 frontend/src/api/client.ts (+1 -0)
📝 frontend/src/components/SpoolFormModal.tsx (+2 -0)
📝 frontend/src/components/spool-form/AdditionalSection.tsx (+55 -9)
📝 frontend/src/components/spool-form/types.ts (+2 -0)

📄 Description

Description

The SpoolWeightPicker component matched catalog entries by weight value only, using find() which returns the first match. This approach is ambiguous when duplicate weights exist in the catalog.
Implemented unique identification using catalog entry IDs:

  • Store the catalog entry ID (unique primary key) whenever a user selects from the catalog
  • When editing, use the ID to look up the exact catalog entry

Fixes #413

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test addition or update

Changes Made

Backend

  • Added core_weight_catalog_id: Mapped[int | None] field to track which catalog entry was used
  • Added core_weight_catalog_id: int | None = None to SpoolBase schema
  • Added core_weight_catalog_id: int | None = None to SpoolUpdate schema
  • Added database migration in run_migrations()

Frontend

  • Updated SpoolFormData interface to include core_weight_catalog_id: number | null

  • Updated defaultFormData to initialize core_weight_catalog_id: null

  • Modified SpoolWeightPicker component signature:

    • Added catalogId and onCatalogIdChange parameters
    • Removed local selectedId state (replaced with catalogId prop)
    • Updated matching logic:
      • Skips auto-matching if catalog hasn't loaded yet (prevents race conditions)
      • Only clears selection if no catalogId exists
      • Keeps valid selections even when multiple entries have same weight
    • Updated display logic to prioritize ID-based lookup over weight-based matching
    • Changed dropdown button click handler to store both weight AND catalog ID
    • Added core_weight_catalog_id to form initialization when editing spools
    • Updated form submission data object to include core_weight_catalog_id
    • Added core_weight_catalog_id to passed props in SpoolWeightPicker call
    • Added core_weight_catalog_id: number | null to InventorySpool interface

Tests

  • "preserves core_weight_catalog_id when editing other fields"
    Verifies catalog ID persists when editing unrelated fields. Edit note → submit → assert core_weight_catalog_id: 5 in PATCH.

  • "includes core_weight_catalog_id when selecting from catalog"
    Verifies both weight and ID sent on creation. Select catalog entry → submit → assert core_weight: 250, core_weight_catalog_id: 2 in POST.

  • "displays correct catalog name when duplicates exist"
    Verifies ID-based lookup works with duplicate weights. Load spool with catalogId: 2 from catalog with duplicate 250g entries → assert "Bambu Lab 250g" displays, not "Generic 250g".

Screenshots

Testing

  • I have tested this on my local machine
  • I have tested with my printer model: H2C

Checklist

  • My code follows the project's coding style
  • I have commented my code where necessary
  • I have updated the documentation (if needed)
  • My changes generate no new warnings
  • I have tested my changes thoroughly

Additional Notes

New test added - please validate


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/maziggy/bambuddy/pull/414 **Author:** [@Keybored02](https://github.com/Keybored02) **Created:** 2/17/2026 **Status:** ✅ Merged **Merged:** 2/18/2026 **Merged by:** [@maziggy](https://github.com/maziggy) **Base:** `0.2.1b` ← **Head:** `feature/filament-fix` --- ### 📝 Commits (6) - [`233f50c`](https://github.com/maziggy/bambuddy/commit/233f50c38db23cf7208a2471b84d517492dd89ac) fix(inventory): spool catalog entry ID matching - [`e17b55f`](https://github.com/maziggy/bambuddy/commit/e17b55fe22ba3441003f81e6cf2c19f6afc4291e) Add tests for core_weight_catalog_id handling - [`b0d341a`](https://github.com/maziggy/bambuddy/commit/b0d341a58aebf3faad3c63a3ee93be4b302e273b) Merge branch '0.2.1b' into feature/filament-fix - [`87c6bfe`](https://github.com/maziggy/bambuddy/commit/87c6bfe67270230d1445d6c429d570e2448396e2) fix(spool-form): improve handling of core_weight_catalog_id and catalog ID selection logic - [`a649a24`](https://github.com/maziggy/bambuddy/commit/a649a246b245f378cd67511c78c832b14424ba64) Merge branch 'feature/filament-fix' of https://github.com/Keybored02/bambuddy into feature/filament-fix - [`72f5bd4`](https://github.com/maziggy/bambuddy/commit/72f5bd445f973058bbedd172ddca7ee280718d46) Merge branch '0.2.1b' into feature/filament-fix ### 📊 Changes **8 files changed** (+206 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `backend/app/core/database.py` (+6 -0) 📝 `backend/app/models/spool.py` (+3 -0) 📝 `backend/app/schemas/spool.py` (+2 -0) 📝 `frontend/src/__tests__/components/SpoolFormModal.test.tsx` (+135 -0) 📝 `frontend/src/api/client.ts` (+1 -0) 📝 `frontend/src/components/SpoolFormModal.tsx` (+2 -0) 📝 `frontend/src/components/spool-form/AdditionalSection.tsx` (+55 -9) 📝 `frontend/src/components/spool-form/types.ts` (+2 -0) </details> ### 📄 Description ## Description The `SpoolWeightPicker` component matched catalog entries by weight value only, using `find()` which returns the first match. This approach is ambiguous when duplicate weights exist in the catalog. Implemented unique identification using catalog entry IDs: - Store the catalog entry ID (unique primary key) whenever a user selects from the catalog - When editing, use the ID to look up the exact catalog entry ## Related Issue Fixes #413 ## Type of Change <!-- Mark the relevant option with an "x" --> - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [x] Test addition or update ## Changes Made ### Backend - Added `core_weight_catalog_id: Mapped[int | None]` field to track which catalog entry was used - Added `core_weight_catalog_id: int | None = None` to `SpoolBase` schema - Added `core_weight_catalog_id: int | None = None` to `SpoolUpdate` schema - Added database migration in `run_migrations()` ### Frontend - Updated `SpoolFormData` interface to include `core_weight_catalog_id: number | null` - Updated `defaultFormData` to initialize `core_weight_catalog_id: null` - Modified `SpoolWeightPicker` component signature: - Added `catalogId` and `onCatalogIdChange` parameters - Removed local `selectedId` state (replaced with `catalogId` prop) - Updated matching logic: - Skips auto-matching if catalog hasn't loaded yet (prevents race conditions) - Only clears selection if no catalogId exists - Keeps valid selections even when multiple entries have same weight - Updated display logic to prioritize ID-based lookup over weight-based matching - Changed dropdown button click handler to store both weight AND catalog ID - Added `core_weight_catalog_id` to form initialization when editing spools - Updated form submission data object to include `core_weight_catalog_id` - Added `core_weight_catalog_id` to passed props in `SpoolWeightPicker` call - Added `core_weight_catalog_id: number | null` to `InventorySpool` interface ### Tests - "preserves core_weight_catalog_id when editing other fields" Verifies catalog ID persists when editing unrelated fields. Edit note → submit → assert `core_weight_catalog_id: 5` in PATCH. - "includes core_weight_catalog_id when selecting from catalog" Verifies both weight and ID sent on creation. Select catalog entry → submit → assert `core_weight: 250, core_weight_catalog_id: 2` in POST. - "displays correct catalog name when duplicates exist" Verifies ID-based lookup works with duplicate weights. Load spool with `catalogId: 2` from catalog with duplicate 250g entries → assert "Bambu Lab 250g" displays, not "Generic 250g". ## Screenshots <!-- If applicable, add screenshots to demonstrate your changes --> ## Testing <!-- Describe how you tested your changes --> - [x] I have tested this on my local machine - [x] I have tested with my printer model: H2C ## Checklist - [x] My code follows the project's coding style - [x] I have commented my code where necessary - [ ] I have updated the documentation (if needed) - [x] My changes generate no new warnings - [x] I have tested my changes thoroughly ## Additional Notes New test added - please validate --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:34:36 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/bambuddy#1033
No description provided.