Skip to content

PR #9 review follow-ups: nil-safe InTxn, doc rename catch-up, Entity[R] tests - #10

Merged
mlwelles merged 6 commits into
mainfrom
fix/pr9-review-followups
Jul 20, 2026
Merged

PR #9 review follow-ups: nil-safe InTxn, doc rename catch-up, Entity[R] tests#10
mlwelles merged 6 commits into
mainfrom
fix/pr9-review-followups

Conversation

@matthewmcneely

@matthewmcneely matthewmcneely commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Follow-ups from a post-merge review of #9, one commit per finding, plus README coverage work that came out of surveying the public API against it.

InTxn(nil) now errors instead of panicking. The package-level InTxn is the advertised constructor for the typed layer, and wrapping a nil Txn deferred a nil-pointer panic to the first method call. A nil tx now yields a ClientTxn carrying a sentinel Txn with initErr set (the same deferred-error contract NewTxn uses for pool failures), so every method reports the error and Query returns nil, matching the failed-transaction contract.

Docs caught up to the 0.9.0 renames. DEFAULTER.md still named LoadOrStore/LoadAndDelete, and VALIDATOR.md still listed the deleted InsertRaw. Both now use the new names, and GetOrInsert appears among the validated writes since validateStruct runs there too.

Direct tests for the Entity[R] base. entity.go shipped in 0.9.0 with no direct coverage; AsRecord's Record() probing was exercised only through hand-rolled wrapper fakes. New tests pin the contract against a generated-style entity: record adoption without copying, the documented pointer-receiver MarshalJSON pitfall (a value-typed entity emits {}), zero-value marshaling to null, lazy UnmarshalJSON allocation, in-place unmarshal of an adopted record, Validate delegating the backing record to the StructValidator, and the AsRecord bridge for a single entity and an element-wise slice.

WithNamespace warning scoped to remote clients. Embedded (file://) clients honor WithNamespace — verified with an insert/query round-trip showing full isolation between a created namespace and the default one — yet NewClient warned "not supported in this version" unconditionally. The warning now fires only for dgraph:// URIs, where v25 namespace support genuinely isn't wired up.

README public-API coverage. The README serves as the repo's primary documentation, so a survey checked every exported symbol in dgdao and dgdao/typed against it. Filled: the four missing client options (WithCacheSizeMB, WithMaxRecvMsgSize, WithGRPCDialOption, WithNamespace), a Defaulter subsection with the DEFAULTER.md link, NewValidator and the VALIDATOR.md link, typed *UniqueError handling, a QueryRaw section, the embedded-engine singleton limitation (ErrSingletonOnly, Shutdown), the Entity[R]/AsRecord generated-entity bridge under dgdao-gen, and a typed capability index table covering the full Query[T] builder surface plus the SetTracer seam and the typed/filter / typed/search companions.

Changelog gets a 0.9.1 entry covering the set.

Testing

go test -short -race . ./typed/ passes locally, matching the unit-test CI job.

🤖 Generated with Claude Code

matthewmcneely and others added 3 commits July 20, 2026 12:58
The 0.9.0 rename sweep covered README and code comments but missed the
two auxiliary docs: DEFAULTER.md still named LoadOrStore/LoadAndDelete,
and VALIDATOR.md still listed the deleted InsertRaw. GetOrInsert now
appears among the validated writes, since validateStruct runs there too.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The package-level InTxn is the advertised public constructor for the
typed layer, and wrapping a nil Txn deferred a nil-pointer panic to the
first method call. A nil tx now yields a ClientTxn carrying a sentinel
Txn with initErr set — the same deferred-error contract NewTxn uses for
pool failures — so every method reports the error and Query returns nil,
matching the failed-transaction contract.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
entity.go shipped in 0.9.0 with no direct tests; AsRecord's Record()
probing was exercised only through hand-rolled wrapper fakes. Pin the
Entity contract against a generated-style entity: record adoption
without copying, the documented pointer-receiver MarshalJSON pitfall
(a value-typed entity emits {}), zero-value marshaling to null, lazy
UnmarshalJSON allocation, in-place unmarshal of an adopted record,
Validate delegating the backing record to the StructValidator, and the
AsRecord bridge for a single entity and an element-wise slice.

Also add the 0.9.1 changelog entry for this follow-up set.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@matthewmcneely
matthewmcneely requested a review from a team as a code owner July 20, 2026 17:00
matthewmcneely and others added 3 commits July 20, 2026 13:26
Embedded (file://) clients honor WithNamespace — the client opens the
given namespace ID with full isolation from the default namespace
(verified by an insert/query round-trip against both) — yet NewClient
warned "namespace is set, but it is not supported in this version"
unconditionally. Gate the warning on the dgraph:// prefix, where v25
namespace support genuinely is not wired up yet.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The README is this repo's primary documentation, so every exported
symbol should be at least discoverable from it. A survey against go doc
found the gaps this commit fills:

- Configuration Options: add WithCacheSizeMB, WithMaxRecvMsgSize,
  WithGRPCDialOption, and WithNamespace (4 of 11 options were missing)
- add a Defaulter subsection and link DEFAULTER.md; mention
  NewValidator and link VALIDATOR.md from the WithValidator section
- Upserting Data: show typed *UniqueError handling via errors.As
- add a Raw DQL Queries (QueryRaw) section, noting it rides ClientCore
  so it works on ClientTxn and the typed client
- Limitations: document the one-embedded-engine-per-process rule
  (ErrSingletonOnly) and how Close/Shutdown release the engine
- dgdao-gen: describe the Entity[R]/AsEntity/Record/AsRecord bridge
- Typed Client: add a capability index table covering the full Query[T]
  builder surface, plus the SetTracer seam and the typed/filter and
  typed/search companion packages

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
staticcheck flags json.Marshal of a struct with no exported fields and
no reachable custom marshaler — which is precisely the pointer-receiver
pitfall TestEntity_MarshalJSONOnValueEmitsEmptyObject exists to pin.
Silence the analyzer at that call site only.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@matthewmcneely
matthewmcneely requested a review from mlwelles July 20, 2026 17:41
@mlwelles
mlwelles merged commit 47bf07e into main Jul 20, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants