Skip to content

Cherry-Pick: Fix: child-config autoentities fails validation with "No entities f… - #3841

Merged
RubenCerna2079 merged 3 commits into
release/2.1from
dev/rubencerna/cherry-pick-autoentities
Sep 30, 2026
Merged

RubenCerna2079 merged 3 commits into
release/2.1from
dev/rubencerna/cherry-pick-autoentities

Conversation

@RubenCerna2079

Copy link
Copy Markdown
Contributor

Why make this change?

What is this change?

Cherry-picked PR:

How was this tested?

This is a cherry-pick it was already tested when it was first merged.

Sample Request(s)

N/A

…ound" when using `data-source-files` (#3723)

## Why make this change?

- Closes #3655
- When a child config (referenced via `data-source-files`) uses
`autoentities` instead of explicit `entities`, validation incorrectly
fails with `"No entities found"`. The same `autoentities` block works
correctly in the top-level config. This contradicts documented behavior
that states every config may satisfy the entities requirement via
`autoentities`.

## What is this change?

- **Root cause**:
`MsSqlMetadataProvider.GenerateAutoentitiesIntoEntities` stores
autoentity resolution counts only on the root (merged)
`RuntimeConfig.AutoentityResolutionCounts`. But `ValidateEntityPresence`
checks the *child* config's own `AutoentityResolutionCounts`, which is
never populated — so the resolved entity count is always 0 for child
configs.

- **Fix** (`RuntimeConfigValidator.ValidateRootConfig`): Before
validating each child config, copy any missing resolution counts from
the root config into the child config. This is a no-op when child counts
are already populated (e.g. in unit tests that pre-populate them
directly).

```csharp
foreach (KeyValuePair<string, Autoentity> ae in childConfig.Autoentities)
{
    if (!childConfig.AutoentityResolutionCounts.ContainsKey(ae.Key)
        && runtimeConfig.AutoentityResolutionCounts.TryGetValue(ae.Key, out int count))
    {
        childConfig.AutoentityResolutionCounts[ae.Key] = count;
    }
}
```

## How was this tested?

- [ ] Integration Tests
- [x] Unit Tests
- `TestChildWithDataSourceAndAutoentitiesResolvingEntitiesIsValid`:
child config with only `autoentities` resolving >0 entities (counts
stored on root only) passes validation — direct regression test for the
bug.
- `TestRootAndChildBothWithAutoentitiesResolvingEntitiesIsValid`: both
root and child have `autoentities`, all counts on root, both pass
validation.

## Sample Request(s)

```json
// dab-config.child.json — previously caused "No entities found" during `dab validate`
{
  "data-source": { "database-type": "mssql", "connection-string": "@env('CONN_B')" },
  "autoentities": {
    "def-b": {
      "patterns": { "name": "b_{object}", "include": [ "dbo.TableTwo" ] },
      "permissions": [ { "role": "anonymous", "actions": [ { "action": "read" } ] } ]
    }
  }
}
```

```bash
dab validate -c dab-config.json  # now passes when child uses autoentities
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: RubenCerna2079 <32799214+RubenCerna2079@users.noreply.github.com>
Co-authored-by: Ruben Cerna <rcernaserna@microsoft.com>
Co-authored-by: Anusha Kolan <anushakolan10@gmail.com>
Co-authored-by: aaronburtle <93220300+aaronburtle@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 30, 2026 17:53
@RubenCerna2079 RubenCerna2079 added 🍒Cherrypick Cherry-picking another commit/PR 2.1 labels Sep 30, 2026
@RubenCerna2079 RubenCerna2079 added this to the September 2026 milestone Sep 30, 2026
@RubenCerna2079 RubenCerna2079 linked an issue Sep 30, 2026 that may be closed by this pull request
@RubenCerna2079 RubenCerna2079 changed the title Fix: child-config autoentities fails validation with "No entities f… Cherry-Pick: Fix: child-config autoentities fails validation with "No entities f… Sep 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The regression test’s root pattern resolves a real table, contradicting and failing to cover its documented zero-resolution scenario.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

Fixes child-config autoentities validation by propagating MSSQL resolution counts to the originating child configuration.

Changes:

  • Associates metadata providers with child configurations.
  • Records autoentity resolution counts on root and child configs.
  • Adds an MSSQL regression test and updates constructor usage.
File Description
src/​Config/​ObjectModel/​RuntimeConfig.cs Adjusts child loading and merged collections.
src/​Core/​Services/​MetadataProviders/​MetadataProviderFactory.cs Maps child configs to metadata providers.
src/​Core/​Services/​MetadataProviders/​MsSqlMetadataProvider.cs Stores child autoentity resolution counts.
src/​Service.Tests/​Caching/​DabCacheServiceIntegrationTests.cs Updates constructor invocation.
src/​Service.Tests/​Configuration/​ConfigurationTests.cs Adds the regression integration test.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs
Comment thread src/Service.Tests/Configuration/ConfigurationTests.cs

@aaronburtle aaronburtle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@RubenCerna2079
RubenCerna2079 merged commit cd004db into release/2.1 Sep 30, 2026
14 checks passed
@RubenCerna2079
RubenCerna2079 deleted the dev/rubencerna/cherry-pick-autoentities branch September 30, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.1 🍒Cherrypick Cherry-picking another commit/PR

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Cherry-pick PRs to branch 2.1

5 participants