Fix bug in MDM command listing - #32992
Conversation
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
WalkthroughAdjusted team filtering in ListMDMCommands to reference the correct derived-table alias from the combined MDM commands subquery. Added tests to validate team-scoped and global command visibility across user roles, including ordering by hostname. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as Caller
participant DS as Datastore (MySQL)
participant Q as ListMDMCommands
participant SQL as getCombinedMDMCommandsQuery
U->>DS: ListMDMCommands(ctx, TeamFilter, opts)
DS->>Q: Build base query
Q-->>DS: Subquery alias: combined_commands
DS->>SQL: Apply team filter on combined_commands.team_id
SQL-->>DS: Filtered result set
DS-->>U: Commands list (with pagination/order)
note over DS,SQL: Team-filter now targets combined_commands alias
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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. Comment Pre-merge checks❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
server/datastore/mysql/mdm.go (1)
96-105: Guard against nil listOpts to avoid nil pointer dereferencelistOpts is dereferenced later (Filters/ListOptions); initialize it when nil to prevent a panic.
func (ds *Datastore) ListMDMCommands( ctx context.Context, tmFilter fleet.TeamFilter, listOpts *fleet.MDMCommandListOptions, ) ([]*fleet.MDMCommand, error) { - if listOpts != nil && listOpts.Filters.HostIdentifier != "" { + if listOpts == nil { + listOpts = &fleet.MDMCommandListOptions{} + } + if listOpts.Filters.HostIdentifier != "" { // separate codepath for more performant query by host identifier return ds.listMDMCommandsByHostIdentifier(ctx, tmFilter, listOpts) }
🧹 Nitpick comments (1)
server/datastore/mysql/mdm.go (1)
83-86: Nit: avoid SELECT * from the derived tableSelecting explicit columns instead of
SELECT *makes the query resilient to schema/column-order changes and can help the optimizer.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
server/datastore/mysql/mdm.go(1 hunks)server/datastore/mysql/mdm_test.go(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go
⚙️ CodeRabbit configuration file
When reviewing SQL queries that are added or modified, ensure that appropriate filtering criteria are applied—especially when a query is intended to return data for a specific entity (e.g., a single host). Check for missing WHERE clauses or incorrect filtering that could lead to incorrect or non-deterministic results (e.g., returning the first row instead of the correct one). Flag any queries that may return unintended results due to lack of precise scoping.
Files:
server/datastore/mysql/mdm.goserver/datastore/mysql/mdm_test.go
🔇 Additional comments (2)
server/datastore/mysql/mdm.go (1)
101-104: Correct alias for team scoping in derived table — good fixUpdating the team filter to use the
combined_commandsalias matches the derived-table alias and prevents the “unknown column h.team_id” error. This correctly scopes results across Apple and Windows rows.server/datastore/mysql/mdm_test.go (1)
36-36: Wires new regression test into the shared suite — looks good.No ordering dependencies detected; the shared TruncateTables call will isolate state between cases.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #32992 +/- ##
==========================================
- Coverage 63.79% 63.79% -0.01%
==========================================
Files 2044 2044
Lines 201367 201371 +4
Branches 6686 6686
==========================================
- Hits 128465 128459 -6
- Misses 62741 62749 +8
- Partials 10161 10163 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #32996
Checklist for submitter
changes/,orbit/changes/oree/fleetd-chrome/changes.See Changes files for more information.
Testing
Summary by CodeRabbit
Bug Fixes
Tests