Skip to content

Throw when the rows under a #[DependsOn] key hold none of its variables - #331

Merged
koriym merged 2 commits into
1.xfrom
depends-on-key-rows
Nov 29, 2026
Merged

koriym merged 2 commits into
1.xfrom
depends-on-key-rows

Conversation

@koriym

@koriym koriym commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

#[DependsOn(uri: ..., key: ...)] now throws DependsOnNotExpandable when the rows under key hold none of the template's variables. The reason is no row under '<key>' holds '<variable>'.

Until now such a variable was read from the body's top level or the onGet() arguments. A row column named apart from the template, such as article_id for #[DependsOn(uri: 'app://self/item?id={id}', key: 'articles')] on onGet(int $id), expanded from the argument: the list depended on item?id=<the argument> instead of its rows, with no error. Without a value of the same name outside, the same mistake already threw.

Unchanged:

  • A template that mixes a row variable with an outside one, such as article?ulid={channelId}-{id}, still reads the outside one.
  • An empty list names no URI; a row that lacks a variable is skipped while other rows hold it.
  • A template without a variable, and a declaration without key.

key is new in 1.21, so this changes no released behaviour. No public type is added. CHANGELOG [Unreleased], the DependsOn/DependsOnNotExpandable docblocks and docs/llms-full.txt are updated. Tests: DependsOnTest::testADeclarationThatCannotExpandThrowsAndStoresNothing (new rows/renamed-column case) and testAVariableTheRowLacksIsReadFromTheTopLevelThenTheArguments.

Summary by CodeRabbit

  • Bug Fixes
    • Dependency expansion now reports a clear error when no keyed row contains any variable needed by the URI template.
    • Rows with missing template variables can use values from the body, helping produce the expected resource links.
  • Documentation
    • Clarified how template values are resolved from keyed rows, the body, and request arguments, and when expansion fails.
    • Documented how empty row lists and one-shot row sources are handled.

A declaration with `key` whose rows hold none of the template's variables now throws
DependsOnNotExpandable ("no row under '<key>' holds '<variable>'"). Such a variable was
read from the body's top level or an argument of the same name, so a column named apart
from the template (`article_id` for `{id}`) expanded from the argument and the rows'
dependencies were lost without an error. A variable no row holds is still read from
outside when the rows hold another variable of the template.
@koriym

koriym commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (bb8fe79) to head (3adb035).

Additional details and impacted files
@@             Coverage Diff             @@
##                 1.x      #331   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       878       887    +9     
===========================================
  Files            121       121           
  Lines           1965      1978   +13     
===========================================
+ Hits            1965      1978   +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 08ab311 and 3adb035.

Files selected for processing: 6

  • docs/llms-full.txt
  • src/DependsOnExpansion.php
  • tests/CACHE_DEPENDENCY_TESTS.md
  • tests/DependsOnTest.php
  • tests/Fake/fake-app/src/Resource/App/Rows/RenamedColumn.php
  • tests/Fake/fake-app/src/Resource/App/Rows/RowMissingPair.php

No actionable comments were generated in the recent review.

Walkthrough

Keyed #[DependsOn] expansion now throws DependsOnNotExpandable when no row under the configured key supplies any URI template variable. The exception identifies the key and variables. Documentation and tests describe the failure and row fallback behavior.

Changes: Keyed URI expansion

Layer / File(s) Summary
Validate keyed rows before expansion
src/DependsOnExpansion.php, src/Exception/DependsOnNotExpandable.php, src-annotation/DependsOn.php, tests/DependsOnTest.php, tests/Fake/fake-app/src/Resource/App/Rows/*, docs/llms-full.txt, CHANGELOG.md
Keyed expansion now throws when no row contains any template variable. The exception message identifies the key and variables. Tests cover row fallback and missing or renamed row fields. Documentation describes the behavior and related variable resolution.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Merge Risk: Minimal · previous review 08ab3

Keyed dependency declarations now fail with a clear error when no row supplies any URI variable, instead of silently expanding from arguments. The change is narrowly scoped, documented and tested, and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main behavior change: DependsOnExpansion::tags() now throws DependsOnNotExpandable when a #[DependsOn] key is set, the URI template has variables, and no row under that key holds a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main behavior change: DependsOnExpansion::tags() now throws DependsOnNotExpandable when a #[DependsOn] key is set, the URI template has variables, and no row under that key holds any of them. The changeset (DependsOnExpansion.php, the exception docblock, CHANGELOG, docs, and tests) matches this.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between bb8fe79 and 08ab311.

Files selected for processing: 8

  • CHANGELOG.md
  • docs/llms-full.txt
  • src-annotation/DependsOn.php
  • src/DependsOnExpansion.php
  • src/Exception/DependsOnNotExpandable.php
  • tests/DependsOnTest.php
  • tests/Fake/fake-app/src/Resource/App/Rows/RenamedColumn.php
  • tests/Fake/fake-app/src/Resource/App/Rows/RowFallback.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

…ot expand

Rows that hold a template variable, but only as an array or a non-Stringable object, now fail
with "'<variable>' is <type>" instead of "no row under '<key>' holds '<variable>'", and a
variable repeated in the template is named once in the reason. Covered by two new
notExpandableProvider cases; docs say the new rule only for rows holding none of the variables.
@koriym
koriym merged commit 58e0f9b into 1.x Nov 29, 2026
44 checks passed
@koriym koriym mentioned this pull request Nov 29, 2026
@koriym

koriym commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review 3adb035 was merged without your review because of the review limit. It names the type in DependsOnNotExpandable's reason when the rows hold a template variable only as a value that cannot expand, and names a repeated variable once.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

Analysis chain

Script executed:

#!/bin/bash
set -uo pipefail
echo '--- commit metadata ---'
git show --format=fuller --no-patch 3adb0354 2>&1 || true
echo '--- commit summary ---'
git show --stat --oneline 3adb0354 2>&1 || true
echo '--- commit diff ---'
git show --format=medium --no-ext-diff --find-renames 3adb0354 -- 2>&1 || true
echo '--- relevant file outlines ---'
for f in src/DependsOnExpansion.php src/Exception/DependsOnNotExpandable.php tests/DependsOnTest.php; do
  if [ -f "$f" ]; then
    echo "--- $f ---"
    ast-grep outline "$f" --items all 2>&1 || true
  fi
done
echo '--- exception files by name ---'
fd -i 'DependsOnNotExpandable'

Length of output: 18504


Script executed:

#!/bin/bash
set -uo pipefail
echo '--- HEAD ---'
git rev-parse HEAD
echo '--- expansion at requested commit ---'
git show 3adb0354:src/DependsOnExpansion.php | nl -ba
echo '--- exception at requested commit ---'
git show 3adb0354:src/Exception/DependsOnNotExpandable.php | nl -ba
echo '--- tests around diagnostics at requested commit ---'
git show 3adb0354:tests/DependsOnTest.php | nl -ba | sed -n '380,535p'
echo '--- variable extraction and expansion call sites ---'
rg -n -C 4 'class DependsOn|function (variables|tags|expandable|isValue|missing)\s*\(|->variables\s*\(|DependsOnExpansion|uriTemplates' src src-annotation tests/DependsOnTest.php
echo '--- candidate helper filenames ---'
fd -i 'UriTemplate|DependsOn' src src-annotation

Length of output: 38398


Script executed:

#!/bin/bash
set -uo pipefail
echo '--- UriTemplates outline ---'
ast-grep outline src/UriTemplates.php --items all
echo '--- UriTemplates variable parsing ---'
cat -n src/UriTemplates.php | sed -n '35,145p'
echo '--- row reading outline ---'
ast-grep outline src/DependsOnRows.php --items all
echo '--- row reading implementation ---'
cat -n src/DependsOnRows.php | sed -n '1,175p'
echo '--- repeated variables and type diagnostics in tests ---'
rg -n -C 3 'repeated|repeat|duplicat|non.Stringable|not Stringable|stdClass|RowMissingPair|row-missing-pair|no row under|is array|is object' tests src docs/llms-full.txt CHANGELOG.md
echo '--- test fixture declarations containing repeated template names ---'
rg -n 'DependsOn\s*\(' tests/Fake/fake-app/src/Resource/App/Rows

Length of output: 53387


@koriym I reviewed commit 3adb0354. I found no functional defects in the changes.

Test gap: RowMissingPair.php Line 15 uses two distinct variables, so the new test does not verify deduplication. I recommend a case such as {id}-{id}-{kind} that expects no row under 'articles' holds 'id' or 'kind'. A non-Stringable object case would also cover the other new type diagnostic.

I inspected the source but could not run the tests in this sandbox.

You are interacting with an AI system.

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