Repository navigation
fix(generator): discover a DocumentDbContext whatever its class name (#300) - #317
Merged
mrdevrobot merged 1 commit intoOct 18, 2026
Conversation
…ntglDb#300) The generator's syntax predicate only passed classes whose name ends in "Context". A DocumentDbContext called Shop, AppDb or Store got no generated code and no diagnostic, so its collection properties stayed null and the first call threw NullReferenceException far from the cause. The predicate now passes every class with a base list; the semantic check in GetDbContextInfo (InheritsFrom DocumentDbContext) already decides, and it is what makes the pre-filter safe to widen. The unused DbContextClassSuffix convention is removed. Tests: UnsuffixedNameFixtures (BLite.Shared) declare a context named Shop and a derived OnlineShop; UnsuffixedNameGeneratorTests check their collections are generated and round-trip. All three fail on upstream/main (collections null, no mapper namespace) and pass with the fix. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
CaffeinatedCoder
had a problem deploying
to
Production
October 18, 2026 11:01 — with
GitHub Actions
Failure
Closed
5 of 72 tasks
Contributor
|
Verified: the three tests fail on 0450b97 (null collections, no mappers) and pass here. Only the "Context" suffix pre-filter is removed; the semantic base-type check still decides. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
The source generator's syntax predicate only passed classes whose name ends in
Context(MapperGenerator.IsPotentialDbContext,MapperGenerator.cs:492-499, since v1.0.0). ADocumentDbContextcalledShop,AppDborStoregot no generated code and no diagnostic. Its collection properties stayednull, and the first call threwNullReferenceExceptionfar from the cause (#300). The README used such a name itself until #298.Fix
The predicate passes every class with a base list. The semantic check in
GetDbContextInfo(InheritsFrom(DocumentDbContext)) already decides what is a context, and it is what makes the pre-filter safe to widen: a class that does not derive fromDocumentDbContextstill produces nothing. The unusedBLiteConventions.DbContextClassSuffixis removed.Cost: the transform now runs
GetDeclaredSymbolfor every class with a base list instead of those named*Context. It is an incremental generator, so the result is cached per node and recomputed only for edited nodes. A name filter cannot be kept as a fast path without reporting the skipped classes, and reporting them needs the same semantic check, so a diagnostic would save nothing.Tests
tests/BLite.Shared/UnsuffixedNameFixtures.csdeclaresShop : DocumentDbContextandOnlineShop : Shop, neither named with the suffix.UnsuffixedNameGeneratorTests, three tests:Shop.Customersis generated and round-trips a document;OnlineShophas both its own and the inherited collection; the mapper namespaceBLite.Shared.Shop_UnsuffixedNameFixtures_Mappersexists.On
upstream/main(checked by revertingsrc/BLite.SourceGenerators) all three fail: the fixture compiles, becauseInitializeCollectionsis a virtual on the base class, but the collections arenulland no mapper namespace exists. With the fix they pass, together with the 47 other generator tests (GlobalNamespace*,DbContextInheritance*,SourceGenerator*).Full suite
dotnet test tests/BLite.Tests(macOS, net10.0): 3094 passed, 4 skipped, 1 failed (IndexPageReleaseTests.DynamicCollection_DropIndex_WhileInserting_KeepsCollectionAndOtherIndexConsistent,TimeoutException: Timed out acquiring collection lock (Insert), while a second suite ran on the same machine; the #303 class of failure, see #302). All 16 tests of that class pass when rerun on their own. This PR changes no runtime code.Compatibility
Contexts that were generated before are generated the same way. A class that derives from
DocumentDbContextand was silently skipped before now gets generated code; if such a class is notpartial, the build now reports that (as it does today for a*Contextclass that is notpartial), which is the intended outcome.Fixes #300
🤖 Generated with Claude Code