Skip to content

Commit 52af4ba

Browse files
densmoeclaude
andauthored
fix: convert UUID to GUID blob in GetRawUnit for v1 MPRs (closes #705) (#711)
GetRawUnit passed the UUID string directly to SQLite for v1 MPR files, but UnitID is stored as a 16-byte GUID blob. The query never matched, returning "no rows" for every lookup on v1 projects (Mendix < 10.18). Apply types.UUIDToBlob() before querying, consistent with getUnitByIDV1() and GetRawUnitBytes() which already do this correctly. Includes regression test with a trimmed Mendix 9.24 v1 MPR fixture. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e39487a commit 52af4ba

4 files changed

Lines changed: 59 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- `GetRawUnit` on v1 MPR files (Mendix < 10.18) — UUID string was passed directly to SQLite instead of being converted to a GUID blob, causing every lookup to fail with "no rows in result set" (#705)
12+
913
## [0.14.0] - 2026-06-21
1014

1115
Headline: **JavaScript actions, clickable containers, and the v0.13.0 enum-visibility regression fixed.** This release adds `CREATE JAVASCRIPT ACTION` authoring and clickable-container support, a new `check` heuristic for `System.owner` XPath constraints, and fixes a v0.13.0 regression that mangled enum literals in conditional-visibility expressions (a release blocker for status-pill authoring).

sdk/mpr/get_raw_unit_v1_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
package mpr
4+
5+
import (
6+
"testing"
7+
8+
"github.com/mendixlabs/mxcli/model"
9+
)
10+
11+
// TestGetRawUnit_V1 verifies that GetRawUnit works on v1 MPR files (Mendix < 10.18)
12+
// where UnitID is stored as a 16-byte GUID blob in SQLite.
13+
// Regression test for https://github.com/mendixlabs/mxcli/issues/705
14+
func TestGetRawUnit_V1(t *testing.T) {
15+
mprPath := "testdata/v1-project/App.mpr"
16+
17+
reader, err := Open(mprPath)
18+
if err != nil {
19+
t.Fatalf("failed to open v1 MPR: %v", err)
20+
}
21+
defer reader.Close()
22+
23+
if reader.Version() != MPRVersionV1 {
24+
t.Fatalf("expected MPR v1, got v%d", reader.Version())
25+
}
26+
27+
// ListAllUnitIDs works correctly (uses blobToUUID internally)
28+
ids, err := reader.ListAllUnitIDs()
29+
if err != nil {
30+
t.Fatalf("ListAllUnitIDs: %v", err)
31+
}
32+
if len(ids) == 0 {
33+
t.Fatal("expected at least one unit ID")
34+
}
35+
36+
// GetRawUnit must be able to retrieve any unit by the ID that ListAllUnitIDs returns.
37+
// Before the fix, this always returned "no rows in result set" on v1 MPRs.
38+
for _, id := range ids {
39+
raw, err := reader.GetRawUnit(model.ID(id))
40+
if err != nil {
41+
t.Errorf("GetRawUnit(%s): %v", id, err)
42+
continue
43+
}
44+
if raw == nil {
45+
t.Errorf("GetRawUnit(%s): returned nil map", id)
46+
continue
47+
}
48+
if _, ok := raw["$Type"]; !ok {
49+
t.Errorf("GetRawUnit(%s): BSON missing $Type field", id)
50+
}
51+
}
52+
}

sdk/mpr/reader_documents.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,9 @@ func (r *Reader) GetRawUnit(id model.ID) (map[string]any, error) {
462462
return nil, fmt.Errorf("failed to read unit contents: %w", err)
463463
}
464464
} else {
465-
// V1: Read from database
466-
row := r.db.QueryRow("SELECT Contents FROM Unit WHERE UnitID = ?", string(id))
465+
// V1: Read from database — convert UUID to GUID blob for the query
466+
unitIDBlob := types.UUIDToBlob(string(id))
467+
row := r.db.QueryRow("SELECT Contents FROM Unit WHERE UnitID = ?", unitIDBlob)
467468
err = row.Scan(&contents)
468469
if err != nil {
469470
return nil, fmt.Errorf("failed to read unit from database: %w", err)
224 KB
Binary file not shown.

0 commit comments

Comments
 (0)