Skip to content

Warn when dab validate finds zero entities in the config#3306

Open
aaronburtle wants to merge 9 commits intomainfrom
dev/aaronburtle/warn-zero-entities-validate
Open

Warn when dab validate finds zero entities in the config#3306
aaronburtle wants to merge 9 commits intomainfrom
dev/aaronburtle/warn-zero-entities-validate

Conversation

@aaronburtle
Copy link
Copy Markdown
Contributor

Why make this change?

Closes #3267

What is this change?

Add a method to check and log a warning when entities are empty when running dab validate.
Added a test case to cover this new behavior.

How was this tested?

New test case covers change in behavior, manually tested with dab validate against zero entities.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a CLI validation-time warning to help users detect “valid” configs that define no entities (and have no autoentities / multi-config datasource files), aligning dab validate behavior with Issue #3267.

Changes:

  • Adds a WarnIfNoEntitiesDefined(RuntimeConfig) helper and invokes it during dab validate.
  • Refactors IsConfigValid to log the new structural warning regardless of overall validation outcome.
  • Adds a CLI unit test that verifies the warning is logged for a minimal config with zero entities.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Cli/ConfigGenerator.cs Introduces and invokes the new “zero entities” warning helper during dab validate.
src/Cli.Tests/ValidateConfigTests.cs Adds a unit test verifying the warning is emitted for an empty-entities config.

@aaronburtle aaronburtle self-assigned this Mar 23, 2026
@aaronburtle aaronburtle added 2.0 bug Something isn't working labels Mar 23, 2026
@aaronburtle aaronburtle moved this from Todo to Review In Progress in Data API builder Mar 23, 2026
@aaronburtle aaronburtle added this to the March 2026 milestone Mar 23, 2026
@anushakolan
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 6 pipeline(s).

Copy link
Copy Markdown
Contributor

@anushakolan anushakolan left a comment

Choose a reason for hiding this comment

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

LGTM, Apart from the minor comment left.

{
if (runtimeConfigProvider.TryGetConfig(out RuntimeConfig? config) && config is not null)
// Run config-structure warnings regardless of validation outcome.
WarnIfNoEntitiesDefined(config);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if there are 0 entities, or autoentities, it is still a valid configuration.

But do we still need to check whether any entity has missing fields when MCP is enabled - i.e. perform the below validation?

We should still Warn if Unauthenticated provider is used with authenticated or custom roles

Copy link
Copy Markdown
Contributor Author

@aaronburtle aaronburtle Apr 3, 2026

Choose a reason for hiding this comment

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

If there are no entities, then the for loop below iterates zero times and this is a no-op, so there wont really be any validation happening; there is nothing to validate. On the other hand, if validation fails for some other reason the user wont see any "missing fields with MCP" warnings, which may be an enhancement we want to add, but shouldn't be scoped to this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Similar to unauthenticated provider with non-anonymous roles. Since it is inside if(isValid) it only fires when everything else passes. If we move it outside then it would always run, but with 0 entities, the warning can never trigger.

Mock<ILogger<ConfigGenerator>> mockLogger = new();
SetLoggerForCliConfigGenerator(mockLogger.Object);

ConfigGenerator.WarnIfNoEntitiesDefined(config!);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Instead of directly calling the WarnIfNoEntitiesDefined function, test the scenario for which the bug is identified.
In this case, can we call IsConfigValid and verify the warning is printed?

Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

Left few comments

WarnIfNoEntitiesDefined(config);

// Additional validation: warn if fields are missing and MCP is enabled
if (isValid)
Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 Apr 3, 2026

Choose a reason for hiding this comment

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

Could you please clarify with @JerryNixon, if it is a config validation error or warning in case:

  1. entities/autoentities both sections are completely missing - i.e. null from the config -> we error out today on this case.
  2. entities/autoentities - either is present but count is 0 - no validation error - but warning emitted as per this PR.

@JerryNixon
Copy link
Copy Markdown
Contributor

JerryNixon commented Apr 3, 2026

Config rules

Level 1. Root config (top level (has a child))

Root rules:

- if data-source-files is empty array, this is a non-Root.
- if data-source-files is NOT empty array, 
    data-source+entities is optional. 

Level 1.1. Non-Root A (including grandchildren)

Non-Root rules:

- must have data source and must have entities (or found entities if auto-entities is configured)
- if has children, same rules as above, must have ds and entities

When to warn

if (IsRoot) // at this point we know it has children
{
    if (has-data-source) // if you have a data source you must have entities
    {
        ValidateItHasEntities();
    }
    else if (!has-data-source && (has-any-entities || has-any-auto-entities-definitions))
    {
        Error("Entities found but no data source defined.");
    }
    else
    {
        Valid();
    }
}
else if (!IsRoot) // non-root/child
{
    ValidateItHasEntities();
}

ValidateItHasEntities()
{
    foreach (var definition in auto-entities-definitions)
    {
        if (definition has no entities)
        {
            Warning($"Auto-entities definition '{definition.Name}' but no entities found.");
        }
    }

    var entityCountFromAutoEntityDefinitions = 123; // count of all autoentities

    if (entityCountFromAutoEntityDefinitions == 0
        && entityCountFromEntities == 0)
    {
        Error("Data source defined but no entities found.");
    }

    Valid();
}

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

Labels

2.0 bug Something isn't working

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

[Bug]: dab validate should at least warn when zero entities are in the config.

5 participants