Skip to content

Add atomic batch creation for stored schedules - #119

Merged
PhiLily merged 1 commit into
mainfrom
feature/create-schedules
Oct 4, 2026
Merged

PhiLily merged 1 commit into
mainfrom
feature/create-schedules

Conversation

@PhiLily

@PhiLily PhiLily commented Oct 4, 2026

Copy link
Copy Markdown
Member

Expose django_ox.stored.create_schedules(rows, *, user=None) as a public,
stable API for schedules that should exist together.

The function validates every row and requires unique names within the
batch. One ValidationError reports every validation failure by row
index, name, field and message. Permission checks follow validation,
with PermissionDenied naming every denied row before any write.

The batch shares one clock reading. A write-only transaction on the
destination database saves every schedule and tells workers once.
A concurrent name conflict raises IntegrityError and rolls back the
whole batch. An empty batch returns [].

What changes for callers

  • Use create_schedules for all-or-nothing batch creation. Pass a list of
    mappings with the fields create_schedule accepts.
  • Read each validation entry's params for index, name, field and
    message. The index is zero-based; field is "" for a failure that
    belongs to no one field.
  • With schedules routed to a database with a narrower integer range,
    create_schedule, update_schedule and the admin form now report field
    errors for values that would previously fail at the database write.
  • Handle ValidationError for non-numeric values in every_seconds,
    phase_seconds or starting_deadline_seconds, phase_seconds=None, mixed
    naive and aware time bounds, and empty values in every_seconds,
    starting_deadline_seconds or end_time. These inputs previously raised
    TypeError in create_schedule and at the validation step in
    update_schedule. In update_schedule, non-numeric every_seconds and
    phase_seconds still raise a ValidationError with no field at an
    earlier step; that behavior is unchanged.
  • On SQLite, create_schedules shares create_schedule's existing limit:
    both fail immediately with "database is locked" inside a caller's
    transaction.atomic() that has already read if another connection
    holds the write lock.

The stored-schedule write functions are documented as public. No
migration is needed. Stored-schedule dispatch is unchanged.

Tests cover each behavior the change adds or alters.

Expose django_ox.stored.create_schedules(rows, *, user=None) as a public,
stable API. Pass a list of mappings with the fields create_schedule
accepts to create schedules that should exist together.

Validate every row and require unique names within the batch. Report
all validation failures in one ValidationError, with row index, name,
field and message. Check permissions only after the whole batch
validates. PermissionDenied names every denied row before any write.

Use one clock reading for the batch. Save all schedules in one
write-only transaction on their destination database and tell workers
once. A concurrent name conflict raises IntegrityError and rolls back
the whole batch. An empty batch returns [].

Validate integer fields against the destination database's range.
create_schedule, update_schedule and the admin form now report field
errors for values that a narrower routed database cannot store.

Report field validation errors for non-numeric values in every_seconds,
phase_seconds or starting_deadline_seconds, phase_seconds=None, mixed
naive and aware time bounds, and empty values in every_seconds,
starting_deadline_seconds or end_time. These inputs previously raised
TypeError in create_schedule and at the validation step in
update_schedule. Callers that handled TypeError for these inputs should
now handle ValidationError. In update_schedule, non-numeric
every_seconds and phase_seconds still raise a ValidationError with no
field at an earlier step; that behavior is unchanged.

Document the stored-schedule write functions as public. No migration
is needed. Stored-schedule dispatch is unchanged.

Tests cover each behavior the change adds or alters.
@PhiLily
PhiLily merged commit 3353110 into main Oct 4, 2026
35 checks passed
@PhiLily
PhiLily deleted the feature/create-schedules branch October 4, 2026 14:14
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.

1 participant