Skip to content

trigger_schedule fails with 422 on 0.33.0.dev server due to force_new_job_creation field #217

Description

@BelhsanHmida

Summary

FlexMeasuresClient.trigger_schedule() can send the legacy snake_case field name force_new_job_creation to the asset scheduling endpoint:

POST /api/v3_0/assets/<id>/schedules/trigger

When this happens against a FlexMeasures 0.33.0.dev* server, the request fails with a 422 response:

{'force_new_job_creation': ['Unknown field.']}

The asset scheduling endpoint appears to expect the newer hyphenated API field name:

"force-new-job-creation": true

Error

ValueError: Request failed with status code 422: {'force_new_job_creation': ['Unknown field.']}

Relevant traceback:

File "examples/HEMS/scheduling.py", line 384, in compute_site_schedules
    job_uuid = await client.trigger_schedule(...)

File "src/flexmeasures_client/client.py", line 1449, in trigger_schedule
    response, status = await self.request(...)

ValueError: Request failed with status code 422: {'force_new_job_creation': ['Unknown field.']}

Reproduction Context

This occurred while running the HEMS example against a local FlexMeasures development server.

Server version example:

0.33.0.dev26+g...

The failing client call uses the asset scheduling endpoint because asset_id is passed:

job_uuid = await client.trigger_schedule(
    start=schedule_start,
    duration=schedule_duration,
    flex_model=final_flex_models,
    asset_id=site_asset["id"],
    prior=current_time,
)

Because prior is provided, the client adds a force-new-job field to bypass the scheduling job cache.

Suspected Root Cause

The client chooses between the legacy and new field names for this schedule-trigger request based on a direct version comparison with 0.33.0.

With Python packaging version semantics:

Version("0.33.0.dev26") < Version("0.33.0")

So a 0.33.0.dev* server is treated as older than 0.33.0, even though it may already expose the 0.33 API shape.

As a result, the client sends:

"force_new_job_creation": true

to the asset scheduling endpoint, which rejects it as an unknown field.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions