fix: omit null color fields from filament/spool responses (fixes AFC lane colors)#3
Open
akira69 wants to merge 1 commit into
Open
fix: omit null color fields from filament/spool responses (fixes AFC lane colors)#3akira69 wants to merge 1 commit into
akira69 wants to merge 1 commit into
Conversation
Two bugs prevented AFC/BoxTurtle lane colors from rendering when
FilaMan is used as a Spoolman drop-in via Moonraker's native
[spoolman] integration.
router.py — add response_model_exclude_none=True to all filament and
spool endpoints (GET, POST, PATCH, PUT /use, PUT /measure).
Real Spoolman omits null fields from responses. Without this setting
FastAPI serialises missing optional fields as JSON null, e.g.
{"color_hex": null, "multi_color_hexes": null, ...}
AFC then does:
cur_lane.color = '#{}'.format(filament['color_hex'])
producing '#None' — an invalid color string — for every filament that
has no colour set, causing lane indicators to render blank.
service.py — return None instead of '' for multi_color_hexes when
a filament has no secondary colours.
An empty string is not a valid absence-of-value marker; returning None
lets response_model_exclude_none drop the field entirely, keeping the
response shape consistent with what a real Spoolman instance returns.
Author
|
I cannot test this, just thought I'd take a swing at it with some AI agents - seems a reasonable proposal. |
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.
Summary
Fixes two bugs that prevented AFC/BoxTurtle lane colors from rendering when FilaMan is used as a Spoolman drop-in via Moonraker's native
[spoolman]integration.Why
Bug 1 —
nullcolor fields break AFC lane coloring (router.py)FastAPI serialises
Noneoptional fields as JSON nulls by default. Withoutresponse_model_exclude_none=True, a filament with no color returns:{"color_hex": null, "multi_color_hexes": null, ...}AFC does:
This produces
"#None"— an invalid color string — for every filament with no color set, causing lane indicators to render blank.Real Spoolman uses
response_model_exclude_none=Trueon all spool/filament endpoints and simply omits null fields. Adding it here restores the same behavior.Bug 2 — Empty string
multi_color_hexesinstead ofNone(service.py)_filament_to_schemareturned""when a filament has no secondary colors. An empty string is not a valid absence-of-value marker —response_model_exclude_noneonly dropsNone, not"". Changed toNoneso the field is properly omitted.Changes
router.py— addresponse_model_exclude_none=Trueto all filament and spool endpoints:GET /filament,GET /filament/{id},POST /filament,PATCH /filament/{id}GET /spool,GET /spool/{id},POST /spool,PATCH /spool/{id},PUT /spool/{id}/use,PUT /spool/{id}/measureservice.py—_filament_to_schema: returnNoneinstead of""formulti_color_hexeswhen no secondary colors are present.Test Checklist
GET /spoolman/api/v1/spool/{id}for a spool with color set:color_hexis present and contains hex without#(e.g."2D6A3F")GET /spoolman/api/v1/spool/{id}for a spool without color set:color_hexfield is absent from the response (notnull)#Nonefor uncolored filaments[spoolman]integration initialises without errors