Fix MissingGreenlet 500 when creating a filament with a color#5
Open
wolfrage76 wants to merge 1 commit into
Open
Fix MissingGreenlet 500 when creating a filament with a color#5wolfrage76 wants to merge 1 commit into
wolfrage76 wants to merge 1 commit into
Conversation
…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.
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.
POST /filament returns HTTP 500 when creating a filament that has a color.
Cause
create_filament()flushes a newFilament, then_apply_filament_colors()runsfilament.filament_colors.append(...). On a freshly-flushed object whosefilament_colorsrelationship was never loaded, the append triggers a lazy load, which raisessqlalchemy.exc.MissingGreenletunder the async (aiosqlite) engine:update_filament()is unaffected because_get_filament()eager-loadsfilament_colorsviaselectinloadbefore_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 = []) beforeadd/flush, so the subsequentappend()operates on a loaded, empty collection and performs no lazy IO. Mirrors how the update path already behaves.Verified:
POST /spoolman/api/v1/filamentreturns 200 and the filament is created with its color.