{"record":{"id":"05320c9f3273104f","repo":"cayleygraph/cayley","slug":"no-context-graph-not-correctly-initialised","errorCode":null,"errorMessage":"No context, graph not correctly initialised","messagePattern":"No context, graph not correctly initialised","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"graph/gaedatastore/quadstore.go","lineNumber":210,"sourceCode":"\t}\n\terr := w.qs.ApplyDeltas(w.deltas, graph.IgnoreOpts{\n\t\tIgnoreDup: true,\n\t})\n\tw.deltas = w.deltas[:0]\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\treturn len(buf), nil\n}\n\nfunc (w *quadWriter) Close() error {\n\tw.deltas = nil\n\treturn nil\n}\n\nfunc (qs *QuadStore) ApplyDeltas(in []graph.Delta, ignoreOpts graph.IgnoreOpts) error {\n\tif qs.context == nil {\n\t\treturn errors.New(\"No context, graph not correctly initialised\")\n\t}\n\ttoKeep := make([]graph.Delta, 0)\n\tfor _, d := range in {\n\t\tif d.Action != graph.Add && d.Action != graph.Delete {\n\t\t\t//Defensive shortcut\n\t\t\treturn errors.New(\"Datastore: invalid action\")\n\t\t}\n\t\tkey := qs.createKeyForQuad(d.Quad)\n\t\tkeep := false\n\t\tswitch d.Action {\n\t\tcase graph.Add:\n\t\t\tfound, err := qs.checkValid(key)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif found {\n\t\t\t\tif !ignoreOpts.IgnoreDup {\n\t\t\t\t\treturn graph.ErrQuadExists","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/cayleygraph/cayley/blob/81dcd7d73e45136bc0d01802a8ba4685d8a533eb/graph/gaedatastore/quadstore.go#L192-L228","documentation":"ApplyDeltas refuses to write any deltas when qs.context is nil, meaning the QuadStore was never initialized with an App Engine request context (getContext failed or was never called). No writes are attempted; the call fails fast.","triggerScenarios":"Calling ApplyDeltas (directly or via WriteQuads, AddQuad, AddQuadSet, RemoveQuad, ApplyTransaction) on a QuadStore whose New/init path did not set qs.context — typically because the HTTPRequest option was missing.","commonSituations":"Initializing the store at package startup without a request, then trying to add quads per-request; a silent earlier getContext error that was ignored; reusing a store across App Engine instances after init failure.","solutions":["Check the error returned at store creation — if it failed, do not use the store.","Initialize the store inside a request handler with the HTTPRequest option so appengine.NewContext succeeds.","Guard all write calls behind a successful initialization check of qs.context.","If context expired, re-initialize the store with a fresh request rather than retrying writes."],"exampleFix":"// before\nif err := qs.AddQuad(q); err != nil { log.Fatal(err) }\n// after\nif qs.context == nil { return errors.New(\"store not initialized with request context\") }\nif err := qs.AddQuad(q); err != nil { log.Fatal(err) }","handlingStrategy":"validation","validationCode":"if qs.context == nil {\n    return errors.New(\"gaedatastore not initialized; pass HTTPRequest at New\")\n}\nfor _, d := range deltas {\n    if d.Action != graph.Add && d.Action != graph.Delete {\n        return fmt.Errorf(\"invalid action %v\", d.Action)\n    }\n}","typeGuard":"func writable(qs *QuadStore) bool { return qs.context != nil }","tryCatchPattern":"if err := qs.ApplyDeltas(deltas, ignoreOpts); err != nil {\n    if strings.Contains(err.Error(), \"not correctly initialised\") {\n        // re-init store with current request, then retry once\n    }\n    return err\n}","preventionTips":["Check store init error before any write call.","Set Action explicitly on every constructed Delta.","Create the store within a request handler scope.","Avoid re-initializing the store concurrently with writes."],"tags":["appengine","initialization","write","state"],"backgroundTag":"invalid-state-transition","analyzedSha":"81dcd7d73e45136bc0d01802a8ba4685d8a533eb","analyzedAt":"2026-09-06T06:14:12.358Z","contentChangedAt":"2026-09-06T06:14:12.358Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}