Skip to content

Commit e470169

Browse files
author
Claude Dev
committed
fix: stale caches cause 'not found' errors for docs created in script transactions
1 parent af266b2 commit e470169

8 files changed

Lines changed: 37 additions & 1 deletion

File tree

cmd/mxcli/examples/helpdesk-app.mdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ create or modify microflow KB.SUB_Article_TruncateContent
746746
returns string as $Preview
747747
folder 'Article'
748748
{
749-
declare $Preview: string = $Article/Content;
749+
$Preview = $Article/Content;
750750
return $Preview;
751751
}
752752
/

mdl/backend/mpr/repos/microflows.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ func (r *microflowRepo) GetContainerUUID(id model.ID) (model.ID, error) {
191191
var blob []byte
192192
err := r.r.DB().QueryRow("SELECT ContainerID FROM Unit WHERE UnitID = ?", bin.Data).Scan(&blob)
193193
if err != nil {
194+
// Fallback: check script-insert buffer for units created in the current
195+
// script transaction but not yet committed to SQLite (Bug B).
196+
if cid, ok := r.r.GetScriptInsertContainerID(string(id)); ok {
197+
return model.ID(cid), nil
198+
}
194199
return "", fmt.Errorf("GetContainerUUID(%s): %w", id, err)
195200
}
196201
return model.ID(mmpr.BlobToUUID(blob)), nil

mdl/backend/mpr/repos/nanoflows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ func (r *nanoflowRepo) GetContainerUUID(id model.ID) (model.ID, error) {
213213
var blob []byte
214214
err := r.r.DB().QueryRow("SELECT ContainerID FROM Unit WHERE UnitID = ?", bin.Data).Scan(&blob)
215215
if err != nil {
216+
if cid, ok := r.r.GetScriptInsertContainerID(string(id)); ok {
217+
return model.ID(cid), nil
218+
}
216219
return "", fmt.Errorf("GetContainerUUID(%s): %w", id, err)
217220
}
218221
return model.ID(mmpr.BlobToUUID(blob)), nil

mdl/backend/mpr/repos/pages.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ func (r *pageRepo) GetContainerUUID(id model.ID) (model.ID, error) {
179179
var blob []byte
180180
err := r.r.DB().QueryRow("SELECT ContainerID FROM Unit WHERE UnitID = ?", bin.Data).Scan(&blob)
181181
if err != nil {
182+
if cid, ok := r.r.GetScriptInsertContainerID(string(id)); ok {
183+
return model.ID(cid), nil
184+
}
182185
return "", fmt.Errorf("GetContainerUUID(%s): %w", id, err)
183186
}
184187
return model.ID(mmpr.BlobToUUID(blob)), nil

mdl/backend/mpr/repos/workflows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ func (r *workflowRepo) GetContainerUUID(id model.ID) (model.ID, error) {
182182
var blob []byte
183183
err := r.r.DB().QueryRow("SELECT ContainerID FROM Unit WHERE UnitID = ?", bin.Data).Scan(&blob)
184184
if err != nil {
185+
if cid, ok := r.r.GetScriptInsertContainerID(string(id)); ok {
186+
return model.ID(cid), nil
187+
}
185188
return "", fmt.Errorf("GetContainerUUID(%s): %w", id, err)
186189
}
187190
return model.ID(mmpr.BlobToUUID(blob)), nil

mdl/executor/cmd_pages_create_v3.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ func execCreatePageV3(ctx *ExecContext, s *ast.CreatePageStmtV3) error {
148148
// Track the created page so it can be resolved by subsequent page references
149149
ctx.trackCreatedPage(s.Name.Module, s.Name.Name, model.ID(genPage.ID()), moduleID)
150150

151+
// Invalidate cached page listing so subsequent findPageIDGen / grant page
152+
// calls see the newly created page (Bug A — stale pagesWithContainerGen).
153+
invalidatePagesGenCache(ctx)
154+
151155
fmt.Fprintf(ctx.Output, "Created page %s\n", s.Name.String())
152156
return nil
153157
}

modelsdk/mpr/reader.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,20 @@ func (r *Reader) ScriptOverlay() map[string][]byte { return r.scriptOverlay }
502502
// ScriptInserts returns the current script insert list (for tests).
503503
func (r *Reader) ScriptInserts() []ScriptInsertEntry { return r.scriptInserts }
504504

505+
// GetScriptInsertContainerID looks up a unit ID in the script-insert buffer
506+
// and returns its container UUID if found. Returns ("", false) when the unit
507+
// is not a buffered insert. This allows GetContainerUUID implementations to
508+
// resolve container linkage for units created within an uncommitted script
509+
// transaction (Bug B — SQLite-only query misses buffered inserts).
510+
func (r *Reader) GetScriptInsertContainerID(unitID string) (string, bool) {
511+
for _, e := range r.scriptInserts {
512+
if e.ID == unitID {
513+
return e.ContainerID, true
514+
}
515+
}
516+
return "", false
517+
}
518+
505519
// blobToUUIDSwapped converts a 16-byte blob to a UUID string using Microsoft GUID format.
506520
// The first 3 groups are little-endian (byte-swapped), last 2 groups are big-endian.
507521
// This is the format used by Mendix for file naming in mprcontents folder.

scripts/validate-academy-capstone.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ run_mxcli() {
121121
if [ -n "${MXCLI:-}" ]; then
122122
"$MXCLI" "$@"
123123
else
124+
# ensure go:embed build artifacts exist before go run
125+
if [ ! -f "$REPO_ROOT/cmd/mxcli/changelog.md" ]; then
126+
make -C "$REPO_ROOT" sync-all 2>/dev/null
127+
fi
124128
(cd "$REPO_ROOT" && go run ./cmd/mxcli "$@")
125129
fi
126130
}

0 commit comments

Comments
 (0)