Skip to content

🐛 Fix mql failure for customGroup defined implicit arrays#6273

Merged
jaym merged 2 commits intomainfrom
mate/fix-buggy-resource_network.routes.first{-}
Dec 9, 2025
Merged

🐛 Fix mql failure for customGroup defined implicit arrays#6273
jaym merged 2 commits intomainfrom
mate/fix-buggy-resource_network.routes.first{-}

Conversation

@Bajusz15
Copy link
Copy Markdown
Contributor

@Bajusz15 Bajusz15 commented Dec 5, 2025

Problem with list resource when defined as implicit array (when defined like []element, there is no failure).
The following query doesn't work as expected:

cnquery> network.routes.first{*}
cannot find field 'list' in resource 'networkRoute'
network.routes.list.first.list: no data available
network {
  interfaces() []networkInterface  // direct array
  routes() networkRoutes // implicit array
}
private networkRoutes {
  []networkRoute // networkRoutes = []networkRoute
  // default routes found on the machine
  defaults() []networkRoute
}

With this change, the query works as expected. Below is explanation:
compileResourceChildAccess returns the wrong type, and then the it fails to access .list.
compileResourceChildAccess should return the child element type, not the implicit array type.

func arrayGetFirstIndexV2(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) {
.....
return &RawData{
   	Type:  bind.Type[1:],
   	Value: arr[0],
   }, 0, nil

Alternatively, we can use network.routes.list.first{*} for now, but network.routes.list.first.list: no data available doesn't look right.

@Bajusz15
Copy link
Copy Markdown
Contributor Author

Bajusz15 commented Dec 5, 2025

@tas50 I'm proposing a fix here, but it needs testing to make sure nothing breaks.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 5, 2025

Test Results

4 656 tests  +1   4 652 ✅ +1   2m 22s ⏱️ +2s
  415 suites ±0       4 💤 ±0 
   31 files   ±0       0 ❌ ±0 

Results for commit bdc0b87. ± Comparison against base commit 55d536a.

♻️ This comment has been updated with latest results.

@tas50 tas50 requested a review from chris-rock December 5, 2025 18:01
@tas50 tas50 changed the title 🐛 Fix buggy resource type 🐛 Fix failures running network.routes.first{*} Dec 6, 2025
@Bajusz15 Bajusz15 changed the title 🐛 Fix failures running network.routes.first{*} 🐛 Fix failure running network.routes.first{*} Dec 8, 2025
@Bajusz15 Bajusz15 changed the title 🐛 Fix failure running network.routes.first{*} 🐛 Fix failures running network.routes.first{*} Dec 8, 2025
@Bajusz15 Bajusz15 requested a review from arlimus December 8, 2025 08:24
@Bajusz15 Bajusz15 changed the title 🐛 Fix failures running network.routes.first{*} 🐛 Fix mql failure for customGroup defined implicit arrays Dec 8, 2025
Comment thread mql/mql_test.go
Comment on lines +262 to +266
{
Code: "customGroups.first.name",
ResultIndex: 0,
Expectation: "group1",
},
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.

Without the fix, this would fail with the following error:

--- FAIL: TestResource_List_Builtins (0.01s)
    --- FAIL: TestResource_List_Builtins/customGroups.first.name (0.00s)
        /Users/matebajusz/go/src/go.mondoo.com/cnquery/mql/testutils.go:107: failed to compile code: cannot find field 'name' in customGroups

Same problem that @tas50 noticed with network.routes

@Bajusz15 Bajusz15 marked this pull request as ready for review December 8, 2025 09:30
Copy link
Copy Markdown
Contributor

@jaym jaym left a comment

Choose a reason for hiding this comment

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

Tested. Compiled code makes more sense now

@jaym jaym merged commit c73ed35 into main Dec 9, 2025
17 checks passed
@jaym jaym deleted the mate/fix-buggy-resource_network.routes.first{-} branch December 9, 2025 15:56
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants