A DocumentDbContext whose class name does not end in "Context" gets no generated code and no diagnostic; its collections stay null
Maintainers usually reply within 2 days
A pull request for this has already been merged.
- #317 by @CaffeinatedCoder — merged
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp
- Domain
- backend, build-system
Research direction
Start with IsPotentialDbContext in src/BLite.SourceGenerators/MapperGenerator.cs and the existing suffix convention in src/BLite.SourceGenerators/Helpers/BLiteConventions.cs. Verify how GetDbContextInfo performs the semantic inheritance check, then inspect the generator tests for coverage of DocumentDbContext subclasses without the Context suffix. Done means such a class produces the expected generated code, or a clearly specified diagnostic explains when it is skipped.
Written by the indexing model from the issue text.
Description
The source generator only looks at classes whose name ends in Context. A DocumentDbContext subclass named anything else (Shop, AppDb, Store, CatalogDb) gets no generated code, and the build reports nothing. Its collection properties stay null, and the first call throws NullReferenceException, far from the cause.
The README used such a name itself until #298 (new AppDb(...) in the master-key and multi-process samples), which is how this was found.
Repro
public class Customer { public ObjectId Id { get; set; } public string Name { get; set; } = ""; }
public partial class ShopContext : DocumentDbContext
{
public DocumentCollection<ObjectId, Customer> Customers { get; set; } = null!;
public ShopContext(string path) : base(path) { }
}
public partial class Shop : DocumentDbContext // same body, different name
{
public DocumentCollection<ObjectId, Customer> Customers { get; set; } = null!;
public Shop(string path) : base(path) { }
}
await using var ok = new ShopContext("a.db"); // ok.Customers is set
await using var db = new Shop("b.db"); // db.Customers is null
await db.Customers.InsertAsync(new Customer { Name = "Ada" }); // NullReferenceException
Build with -p:EmitCompilerGeneratedFiles=true: the generator emits GenCheck.ShopContext_Program.Mappers.g.cs and nothing for Shop; no BLITE diagnostic.
Expected: a class that derives from DocumentDbContext is generated whatever its name, or the build says why it is not.
Actual: silently skipped.
Where in the code (0450b97)
MapperGenerator.IsPotentialDbContext(src/BLite.SourceGenerators/MapperGenerator.cs:492-499) filters onclassDecl.Identifier.Text.EndsWith(BLiteConventions.DbContextClassSuffix), withDbContextClassSuffix = "Context"(src/BLite.SourceGenerators/Helpers/BLiteConventions.cs:13). The filter has been there since the generator's first version (219efaa, v1.0.0).GetDbContextInfo(MapperGenerator.cs:805-813) then checks semantically that the class inherits fromDocumentDbContext, so the name filter is only a cheap pre-filter, and it drops real contexts.- Neither the README nor the XML docs of
DocumentDbContextmention the naming rule.
Suggested fix
- Drop the name condition from the syntax predicate (
ClassDeclarationSyntaxwith aBaseListis cheap enough; the semantic check already decides), or - keep it as a fast path, and report a warning (BLITE00x) for any class that derives from
DocumentDbContextbut was skipped, naming the rule. - Test: a context named without the suffix is generated (or the diagnostic is reported), in the generator tests.
Related: #152 (contexts in the global namespace, the same kind of silent skip), #298.
- Dominant language
- C#
- Stars
- 66
- Forks
- 6
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 58
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EntglDb/BLite
-
GdprMode.Strict warns that deleted documents are not zeroed, but every delete zero-fills themPossibly taken @CaffeinatedCoder claimed this 2 days ago. Openbug gdpr package/core severity/low
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
EntglDb/BLite#299 · 1 comment ·
Maintainers usually reply within 2 days
-
bug package/core severity/medium triage
Difficulty 4/5 3-5 days Newbie friendliness 54/100
Maintainers usually reply within 2 days
-
bug package/core severity/medium
Difficulty 4/5 3-5 days Newbie friendliness 48/100
EntglDb/BLite#322 · 1 comment ·
Maintainers usually reply within 2 days
-
enhancement package/core
Difficulty 4/5 3-5 days Newbie friendliness 48/100
EntglDb/BLite#320 · 1 comment ·
Maintainers usually reply within 2 days
-
BLiteSession.Rollback() does not await the rollback: it returns while the transaction is still active, and failures go unobservedPossibly taken @CaffeinatedCoder claimed this 2 days ago. Openbug package/core severity/medium
Difficulty 3/5 1-2 days Newbie friendliness 78/100
EntglDb/BLite#307 · 1 comment ·
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
gavin-wolfe/wolfden#104 ·
Maintainers usually reply within 1 day
-
[BUG] Still libmicrohttpd dependency is not removed properly from External-Dependency-Info.txt fileOpentype/bug
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
[辞書] かんそうりつ->乾燥率Open辞書
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
thomhurst/TUnit#7201 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
ArduPilot/MissionPlanner#3826 ·
Maintainers usually reply within 1 day