lablup / lablup/backend.ai

Render JSONB partial updates inside PydanticColumn via JsonbMerge

Open
#14,470 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
21h 49m
Merged PRs (30d)
404

Description

TriState / OptionalState decide whether a column is written. Inside a JSONB column storing a Pydantic model there is no counterpart, so an updater rebuilds the whole document from whatever the request carried and the keys the request omitted fall back to their defaults.

Confirmed live cases: resource_slot_types.number_format sending only binary resets round_length; scaling_groups.scheduler_opts.preemption sending one field resets the other five; prometheus_query_presets.options needs one hand-written jsonb_set branch per combination of fields.

### Change

- PydanticColumn learns the column it is attached to (TypeDecorator is a SchemaEventTarget) and renders a partial update itself in bind_expression.
- A bound JsonbMerge is written as a recursive merge onto the stored document, so sibling keys the patch does not mention survive. Any other value replaces the document whole, unchanged from today.
- PydanticListColumn refuses a JsonbMerge: on an array the concatenation operator appends instead of merging, which would corrupt the document without raising.
- First application: the prometheus query preset updater drops its per-combination jsonb_set branching.

### Scope

No API or schema change. Exposing partial updates on the preemption and number_format request DTOs widens GraphQL input types and is filed separately.

### Verification

A test collects every declared PydanticColumn and PydanticListColumn from the mapped metadata and runs the same scenarios against each, so a column added later is covered without editing the test.

Known limit: a JsonbMerge bound into an INSERT references the target column in VALUES and PostgreSQL rejects it. The hook cannot see the statement kind; the behaviour is asserted so it is a known one.

JIRA Issue: BA-7795

Contributor guide

Open the contributing guide

Research direction

Start with PydanticColumn, PydanticListColumn, JsonbMerge, and their bind_expression and mapped-metadata entry points, then inspect the prometheus query preset updater. Run the metadata-wide test against every declared column, including the known INSERT case; done means partial JSONB updates preserve omitted sibling keys, list columns reject JsonbMerge, and the updater no longer needs per-combination jsonb_set branches.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python, sqlalchemy
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.