Skip to content

Fix MissingGreenlet 500 when creating a filament with a color#5

Open
wolfrage76 wants to merge 1 commit into
Fire-Devils:mainfrom
wolfrage76:fix-create-filament-missinggreenlet
Open

Fix MissingGreenlet 500 when creating a filament with a color#5
wolfrage76 wants to merge 1 commit into
Fire-Devils:mainfrom
wolfrage76:fix-create-filament-missinggreenlet

Conversation

@wolfrage76

Copy link
Copy Markdown

POST /filament returns HTTP 500 when creating a filament that has a color.

Cause

create_filament() flushes a new Filament, then _apply_filament_colors() runs filament.filament_colors.append(...). On a freshly-flushed object whose filament_colors relationship was never loaded, the append triggers a lazy load, which raises sqlalchemy.exc.MissingGreenlet under the async (aiosqlite) engine:

greenlet_spawn has not been called; can't call await_only() here.

update_filament() is unaffected because _get_filament() eager-loads filament_colors via selectinload before _apply_filament_colors() runs.

Impact

Any client that creates a filament with a color hits this. It is reliably reproduced via Bambuddy: saving a profile on two spools that share a single filament makes Bambuddy create a per-spool filament (POST /filament), which 500s and surfaces in the UI as "Spoolman is not reachable".

Fix

Initialize the collection on the new object (filament.filament_colors = []) before add/flush, so the subsequent append() operates on a loaded, empty collection and performs no lazy IO. Mirrors how the update path already behaves.

Verified: POST /spoolman/api/v1/filament returns 200 and the filament is created with its color.

…olor

create_filament() flushes a new Filament, then _apply_filament_colors()
does filament.filament_colors.append(...). On a freshly-flushed,
never-loaded relationship this triggers a lazy load, which raises
sqlalchemy.exc.MissingGreenlet under the async (aiosqlite) engine:

    greenlet_spawn has not been called; can't call await_only() here.

The result is HTTP 500 from POST /filament. Clients that create a
filament as part of saving a spool (e.g. Bambuddy splitting two spools
that share one filament) surface this as "Spoolman is not reachable".

update_filament() is unaffected because _get_filament() eager-loads
filament_colors via selectinload before _apply_filament_colors() runs.

Initialize the collection on the new object (filament.filament_colors = [])
before add/flush so the subsequent append() operates on a loaded,
empty collection and performs no lazy IO.
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