Warn when dab validate finds zero entities in the config#3306
Warn when dab validate finds zero entities in the config#3306aaronburtle wants to merge 9 commits intomainfrom
Conversation
There was a problem hiding this comment.
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 duringdab validate. - Refactors
IsConfigValidto 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. |
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
anushakolan
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!); |
There was a problem hiding this comment.
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?
| WarnIfNoEntitiesDefined(config); | ||
|
|
||
| // Additional validation: warn if fields are missing and MCP is enabled | ||
| if (isValid) |
There was a problem hiding this comment.
Could you please clarify with @JerryNixon, if it is a config validation error or warning in case:
- entities/autoentities both sections are completely missing - i.e. null from the config -> we error out today on this case.
- entities/autoentities - either is present but count is 0 - no validation error - but warning emitted as per this PR.
Config rules
Root rules:
Non-Root rules:When to warnif (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();
} |
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 validateagainst zero entities.