Skip to content

fix(postgres): explicit owner via relation no longer breaks creates on readonly-default columns (v0.30.6)#45

Open
scoop1120 wants to merge 1 commit into
mainfrom
fix/ownership-explicit-owner-create
Open

fix(postgres): explicit owner via relation no longer breaks creates on readonly-default columns (v0.30.6)#45
scoop1120 wants to merge 1 commit into
mainfrom
fix/ownership-explicit-owner-create

Conversation

@scoop1120

Copy link
Copy Markdown
Contributor

Problem

Entities generated with @ownership auto-assign have a readonly owner column (e.g. owner_uuid) with a dynamic default from the auth context. When a creation input also supplied that column via the many-to-one relation (owner: { uuid }), the INSERT named the column twice:

INSERT INTO "lessons" (..., "owner_uuid", "owner_uuid") VALUES (...)
-- Postgres 42701: column "owner_uuid" specified more than once

The client saw only the masked Operation failed. This broke lesson/play creation in jrnba_app whenever an explicit owner was sent (including admin view-as / on-behalf creation, which has no workaround without this fix).

Changes (create_data_param_mapper.rs)

  1. map_readonly_defaults: skip a readonly field's dynamic default when the argument already supplies that column via another input field (scalar or many-to-one relation). The relation-supplied value wins and the INSERT stays valid.
  2. enrich_argument_for_access (reverse enrichment, relation → FK scalar): create-access expressions like self.owner_id == AuthContext.id now evaluate against the owner supplied via the relation instead of treating it as a missing value. Without this, change (1) alone would let restricted callers create rows owned by other users — caught during verification and closed here.

Tests

New suite integration-tests/readonly-relation-owner (readonly owner column + relation alias on the same column):

Case Old engine This PR
create without owner (auto-assign) pass pass
create with owner = self FAIL (42701) pass
create with owner = another user FAIL (wrong error, masked) pass (Not authorized)

Also verified: cargo test -p postgres-graphql-resolver -p postgres-core-builder (68 tests), and the readonly, create-access-residue, access-in-context-residue, default-values, default-access, access-expressions integration suites all pass.

End-to-end verification against the real app schema + database lives in vreps-exo tests/integration/content-creation.test.ts (4-case matrix incl. admin on-behalf), run against this build.

Version

Bumps 0.30.5 → 0.30.6 (scripts/bump-version.sh patch). After merge: cut the release tag and bump EXOGRAPH_TAG for staging/production in vreps-exo.

🤖 Generated with Claude Code

…relations; enforce access on relation-supplied owners

Entities using @Ownership auto-assign have a readonly owner column with a
dynamic default (AuthContext.userId). When a create input also supplied the
same column through a many-to-one relation (owner: { uuid }), the INSERT named
the column twice — Postgres rejected it with 42701 ("column specified more than
once") and clients saw a masked "Operation failed". This broke lesson/play
creation in the app whenever an explicit owner was sent.

Two changes in create_data_param_mapper:

1. map_readonly_defaults now skips a readonly field's dynamic default when the
   argument already supplies that column via another input field (scalar or
   many-to-one relation), so the relation value wins and the INSERT stays valid.

2. enrich_argument_for_access gains the reverse enrichment (relation -> FK
   scalar): access expressions like `self.owner_id == AuthContext.id` now
   evaluate against the owner supplied via the relation instead of treating it
   as a missing value. Without this, (1) would let restricted callers create
   rows owned by other users.

Adds integration-tests/readonly-relation-owner covering auto-assign, explicit
owner = self (previously the duplicate-column failure), and explicit owner =
another user (must be denied). The two explicit-owner tests fail on the
previous engine and pass with this change.

Bumps version 0.30.5 -> 0.30.6.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the fix label Jul 14, 2026
@github-actions

Copy link
Copy Markdown

Version bump detected: 0.30.50.30.6

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant