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
Open
Conversation
…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>
|
Version bump detected: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Entities generated with
@ownershipauto-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: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)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.enrich_argument_for_access(reverse enrichment, relation → FK scalar): create-access expressions likeself.owner_id == AuthContext.idnow 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):Not authorized)Also verified:
cargo test -p postgres-graphql-resolver -p postgres-core-builder(68 tests), and thereadonly,create-access-residue,access-in-context-residue,default-values,default-access,access-expressionsintegration 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 bumpEXOGRAPH_TAGfor staging/production in vreps-exo.🤖 Generated with Claude Code