Skip to content

POST /norm-expansion/norms/ returns 500 and rolls back (MissingGreenlet in NormResponse serialization) #442

Description

@mherrerap87

Version: 16.0.0 (Docker, linux/amd64) · Endpoint: POST /api/v1/norm-expansion/norms/

Creating a norm via the API fails with HTTP 500 and — more importantly — the transaction
is rolled back, so the norm is not persisted even though it was created in the session.

Backend log:

pydantic_core._pydantic_core.ValidationError: 1 validation error for NormResponse
  Error extracting attribute: MissingGreenlet: greenlet_spawn has not been called;
  can't call await_only() here. Was IO attempted in an unexpected place?
  input_value=<ProductionNorm sc-mo-038 (m2)>

This looks like the same class of bug fixed for budgets in v16.0.0 (response
serialization triggering a lazy load under async SQLAlchemy → session.refresh()
before serializing). Reproduced with a minimal body:

{"work_key": "sc-mo-038", "name": "Test norm", "unit": "m2",
 "category": "Test", "labor_hours_per_unit": 1.5, "notes": "test", "is_active": true}

Result: 500 + SELECT count(*) FROM oe_norm_expansion_norm WHERE work_key='sc-mo-038' → 0.

Note: machine_hours_per_unit also has a NOT NULL constraint in the DB while the API
schema marks it nullable — sending null fails with an IntegrityError; 0 works.
Workaround we used: direct SQL insert. Happy to test a fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions