Skip to content

fix: use Python-level default for Specification.complexity to prevent MissingGreenlet error#1176

Open
octo-patch wants to merge 5 commits into
Pythagora-io:mainfrom
octo-patch:fix/issue-1105-specification-complexity-default
Open

fix: use Python-level default for Specification.complexity to prevent MissingGreenlet error#1176
octo-patch wants to merge 5 commits into
Pythagora-io:mainfrom
octo-patch:fix/issue-1105-specification-complexity-default

Conversation

@octo-patch

Copy link
Copy Markdown

Fixes #1105

Problem

Specification.complexity was declared with server_default=Complexity.HARD. A server_default only 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, accessing self.complexity returns None, which causes SQLAlchemy to attempt a lazy IO operation outside an async greenlet context, raising:

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

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

  • Change server_default=Complexity.HARDdefault=Complexity.HARD so 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.
  • Add or Complexity.HARD fallback in clone() to safely handle any existing rows in the database that have a NULL complexity 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

  • Reproduced the error by instantiating a Specification without flushing, then calling clone()
  • Confirmed that after the fix, complexity is immediately available as "hard" without a database round-trip

Zvonimir Sabljic and others added 5 commits August 24, 2025 13:37
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>
@CLAassistant

CLAassistant commented Apr 28, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 4 committers have signed the CLA.

❌ Zvonimir Sabljic
❌ MarkoBosnjak98
❌ LeonOstrez
❌ github-actions[bot]


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.

@LeonOstrez LeonOstrez force-pushed the main branch 2 times, most recently from 90f59f5 to a372904 Compare June 8, 2026 11:13
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.

[Bug]: Error When Running the Program from the Command Line

4 participants