fix: use Python-level default for Specification.complexity to prevent MissingGreenlet error#1176
Open
octo-patch wants to merge 5 commits into
Open
Conversation
This reverts commit 17923847f40863e977588d1a81bec2ae16e9801f.
… MissingGreenlet error (fixes Pythagora-io#1105) `server_default` only sets a DB-level default that requires a round-trip to the database before the value is available on the Python object. When `clone()` is called before the first commit, `self.complexity` is `None`, causing SQLAlchemy to attempt a lazy IO fetch outside an async greenlet, raising `MissingGreenlet`. Switch to `default=Complexity.HARD` so the value is set at the Python level on instantiation, matching how all other string columns in this model are configured. Also add an `or Complexity.HARD` fallback in `clone()` to guard against rows in existing databases that have a NULL complexity value. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
|
Zvonimir Sabljic seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
90f59f5 to
a372904
Compare
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.
Fixes #1105
Problem
Specification.complexitywas declared withserver_default=Complexity.HARD. Aserver_defaultonly provides a database-level DEFAULT clause; SQLAlchemy does not set the attribute value at the Python level when the object is first created. Before the object is committed and the row is fetched back from the database, accessingself.complexityreturnsNone, which causes SQLAlchemy to attempt a lazy IO operation outside an async greenlet context, raising:This crash happens in
Specification.clone()on line 55 when the spec object has been created but not yet persisted (or when an existing DB row has a NULL complexity from an older migration).Solution
server_default=Complexity.HARD→default=Complexity.HARDso SQLAlchemy sets the value on the Python object at instantiation time, consistent with how all other string columns (description,architecture, etc.) are configured in this model.or Complexity.HARDfallback inclone()to safely handle any existing rows in the database that have aNULLcomplexity value.No database migration is needed: the schema-level DEFAULT was already applied by the original
server_default; this change only affects Python-side attribute initialization.Testing
Specificationwithout flushing, then callingclone()complexityis immediately available as"hard"without a database round-trip