Skip to content

Answer 500, not 503, when a household job's create may have been committed #1089

Closed

Description

@anth-volk

What happens now

POST /household-calculations creates the household job in one transaction: it inserts the household_jobs row and commits. HouseholdJobStore.create_job lets every SQLAlchemyError through unchanged, and HouseholdCalculationService._create answers each with 503 database_unavailable (logged as household_job_not_created).

When the connection fails during the commit, PostgreSQL may already have applied it, so the job may exist. The Public API reads sim's coded 503 as "no job of the submission will run" and tells its caller so. A resubmission then creates a second job.

What should happen

Do what the economy and household report routes already do (#1052): when the commit fails after the job's row was inserted, answer the JSON 500 internal_error, which the Public API reads as "the job may exist", start no Modal call, and log the failure with the commit error's type. Answer 503 database_unavailable only when nothing was written. A refused reference stays 400 missing_reference, and a normal submission is unchanged.

The Public API needs no change: its household adapter (policyengine_api/libs/simulation_household_calculations.py) already reads sim's 500 as a job that may exist.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions