Skip to content

fix: omit null color fields from filament/spool responses (fixes AFC lane colors)#3

Open
akira69 wants to merge 1 commit into
Fire-Devils:mainfrom
akira69:fix/color-hex-null-serialization
Open

fix: omit null color fields from filament/spool responses (fixes AFC lane colors)#3
akira69 wants to merge 1 commit into
Fire-Devils:mainfrom
akira69:fix/color-hex-null-serialization

Conversation

@akira69

@akira69 akira69 commented May 29, 2026

Copy link
Copy Markdown

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 — null color fields break AFC lane coloring (router.py)

FastAPI serialises None optional fields as JSON nulls by default. Without response_model_exclude_none=True, a filament with no color returns:

{"color_hex": null, "multi_color_hexes": null, ...}

AFC does:

cur_lane.color = '#{}'.format(filament['color_hex'])

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=True on all spool/filament endpoints and simply omits null fields. Adding it here restores the same behavior.

Bug 2 — Empty string multi_color_hexes instead of None (service.py)

_filament_to_schema returned "" when a filament has no secondary colors. An empty string is not a valid absence-of-value marker — response_model_exclude_none only drops None, not "". Changed to None so the field is properly omitted.

Changes

router.py — add response_model_exclude_none=True to 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}/measure

service.py_filament_to_schema: return None instead of "" for multi_color_hexes when no secondary colors are present.

Test Checklist

  • GET /spoolman/api/v1/spool/{id} for a spool with color set: color_hex is present and contains hex without # (e.g. "2D6A3F")
  • GET /spoolman/api/v1/spool/{id} for a spool without color set: color_hex field is absent from the response (not null)
  • AFC/BoxTurtle lane colors render correctly for colored filaments
  • AFC/BoxTurtle lane indicators do not show #None for uncolored filaments
  • Moonraker [spoolman] integration initialises without errors

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.
@akira69

akira69 commented May 29, 2026

Copy link
Copy Markdown
Author

I cannot test this, just thought I'd take a swing at it with some AI agents - seems a reasonable proposal.

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