Registry Mirror
Skip to content

Conversation

@grandnode-dev

@grandnode-dev grandnode-dev commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Type: feature

Issue

#1131 enabled nullable reference types everywhere except the plugins (src/Plugins) and the test projects (src/Tests). Those two still compiled without nullable, so a plugin could pass or return null where the core now says it cannot, and the tests did not show where a null was used.

Solution

The 20 plugins and the 22 test projects compile with nullable enabled and nullable warnings as errors, and the setting moved into Grand.Common.props: every project that imports it starts that way, a new plugin included. The per-project settings and the 27 #nullable enable directives are gone. The two Aspire projects do not import the props and keep their own setting.

The rules are those of #1131 (.ai/knowledge/dotnet.md, Nullable Reference Types). Nothing is silenced, no ! is left in the plugins, and a test passes null! only where the null exercises the guard of the code under test.

One commit per layer:

  1. Plugins. Models and settings strings are nullable. The ! BrainTree, OnAccount and Google Analytics carried from before are gone.
  2. Declare the nulls the code already handles. 13 production signatures that take null by design, found by the tests (listed below).
  3. Tests.
    • [TestInitialize] became the constructor (MSTest builds an instance per test). An async initializer keeps only its awaits.
    • A value that may be null is asserted before use: Assert.IsNotNull, Assert.IsInstanceOfType<T> for a view model or JSON value, First where the test expects the element.
    • Moq setups of methods returning Task<T?> use ReturnsAsync.
    • A null where the parameter takes none became the neutral value of the type ("", [], new()), or null! in a test about the missing value.
  4. Tests added on develop meanwhile (Validate the antiforgery token on the panel two-factor sign-in #1132-Build develop again: the push settings escaping takes a setting that may be null #1142), under the same rules.
  5. Grand.Common.props.

Contract changes

  • DiscountRuleValidationRequest: Discount, DiscountRule, Customer and Store are required and not null. The one place that creates it always set all four, so every discount rule now gets them non-null.
  • PanelStoreId() moved from Grand.Web.AdminShared to Grand.Web.Common. The plugins' Store-area controllers read the staff store the same way Grand.Web.Store does, and throw when it is missing.
  • Nulls the code already handled, now in the signature:
    • IContactAttributeParser.FormatAttributes(… DomainHost? host …).
    • The LiquidCustomer, LiquidOrder and LiquidMerchandiseReturn host. Each falls back to the store URL.
    • DataSettingsManager.LoadDataSettings(DataSettings?): null forgets the loaded settings.
    • The PluginInfo constructor (a plugin that failed to load has no assembly).
    • The audit log List / HistoryPopup / HistoryList query parameters.
    • CustomerList searchCustomerTagIds, which the store panel passes as null.
    • PrepareKnowledgebaseNodeGridModel(string? parentCategoryId), where null is the root.
  • ICountryService.GetStateProvincesByCountryId returns Task<IList<StateProvince>>: it already gave an empty list for a missing or unknown country, so the callers dropped their ?? []. The standard discount rules dropped their request.Customer == null checks, now that the customer is required.
  • Merchandise return note: a note without an attached file binds its file as null. InsertMerchandiseReturnNoteCommand.File is no longer required and the action takes IFormFile?. Enable nullable reference types #1131 had marked it required.

Behaviour changes

All in the plugins, where develop threw a NullReferenceException or answered 500:

  • Sign-in: Facebook and Google sign-in without a NameIdentifier claim goes back to the login page.
  • Stripe webhook: without a Stripe-Signature header it answers 400 as before, now from an explicit check that says so.
  • Admin, missing records: a shipping point edit or delete answers like the Store-area controllers do (back to the list, or an empty answer). The same goes for a country/state/zip tax rate update. Develop answered 500.
  • Shipping point checkout: without offered options it asks to select a point again.
  • Explicit exceptions with a message instead of an NRE:
    • an ECB/NBP response without the expected nodes;
    • a BrainTree payment whose customer or billing address is missing, or which runs outside a request;
    • Stripe without an API key or order line;
    • a Stripe redirect for an order that does not exist.

Breaking changes

  • Every project that imports Grand.Common.props now builds with nullable warnings as errors. A third-party plugin or module that imports it, and was built without nullable, has to fix its nullable warnings or turn the setting off in its own project file.
  • DiscountRuleValidationRequest's members are required (CS9035 regardless of the nullable setting), so code that creates one must set all four. No plugin in this repository creates one.
  • PanelStoreId() changed namespace: it is now in Grand.Web.Common.Extensions, no longer in Grand.Web.AdminShared.Extensions. It was added by Enable nullable reference types #1131 and has not been released.
  • Grand.Common.props appends nullable to WarningsAsErrors ($(WarningsAsErrors);nullable), so a value set before the import is kept.

Testing

  • After the review fixes (3bf3995, 4e0ef76): the solution builds with 0 errors; the Business.Common, Business.Catalog, Web and Modules tests pass.
  • The whole solution builds from clean with nullable warnings as errors: 0 errors, 0 warnings.
  • All 22 test projects pass, the same tests as on develop plus the ones develop added meanwhile.
  • Two test fixes on the way:
    • PriceServiceTests set the working currency on its mock before creating the currency, so the mock returned null. The currency is now created first.
    • SeNameServiceTests (NUnit) runs an instance per test case, so its constructor replaces [SetUp].
  • End to end, plugins only: fresh installs with sample data of this branch's plugin commit and of develop's merge base, side by side, with the same script. Every result line compared.
    • Configuration: every configuration page of every plugin (14 in Admin, 8 in the Store panel), opened, saved back unchanged and compared field by field. Saving real values (Google Analytics, Facebook Pixel, cash on delivery).
    • Plugin records: shipping by weight rates, fixed shipping and tax rates, shipping points, country/state/zip tax rates and slides, each also with unknown ids. All five discount rule types.
    • Storefront: the three themes (Default, Modern, Nordic) with the widgets. Checkout with every shipping method (by weight $7.60, fixed rate $4.00, shipping point with its $3.00 fee), cash on delivery in every theme, BrainTree, Stripe and on account. On account was paid for by a customer with trade credit, with the due date exactly the payment term ahead, and was hidden from a customer whose credit is too small.
    • Endpoints: the Google and Facebook callbacks without a provider answer, the Stripe webhook with no or a bad signature, the shipping point and payment info endpoints.
    • Result: the same results as develop everywhere, except the 500s listed under behaviour changes, which this branch answers without an error.

Found, not changed (develop has them too)

The review of this PR found more; each is fixed in its own PR from develop: #1146, #1147, #1148, #1149, #1150, #1151, #1152.

support added 5 commits November 28, 2026 12:06
The 20 shipped plugins now compile with nullable enabled and nullable
warnings as errors, like the core projects. Models and settings strings
are nullable; no warning is suppressed and no `!` is left: the ones
BrainTree, OnAccount and Google Analytics carried from before are gone.

Contract changes:
- DiscountRuleValidationRequest: Discount, DiscountRule, Customer and
  Store are required and not null. The one caller always set all four.
- PanelStoreId() moved from AdminShared to Grand.Web.Common, so the
  plugins' Store-area controllers read the staff store id the way
  Grand.Web.Store does, and throw when it is missing.

Behaviour where develop would throw a NullReferenceException:
- Facebook/Google sign-in without a NameIdentifier claim goes back to
  the login page.
- Stripe webhook without a Stripe-Signature header answers 400 as
  before, from an explicit check.
- Explicit exceptions with a message instead: ECB/NBP response without
  the expected nodes, BrainTree payment whose customer or billing
  address is missing or which runs outside a request, Stripe without an
  API key or order line, Stripe redirect for a missing order.
- Admin shipping point edit/delete and admin tax rate update of a
  missing record redirect or answer empty, as the Store-area ones do.
- Shipping point checkout without offered options asks to select a
  point again.
With the tests compiled under nullable, they showed parameters that take
null by design while their type said otherwise. Each one below is
already handled where it is used, and a test pins that behaviour:

- FormatAttributes host (IContactAttributeParser): documented as
  optional, read with host?.Url.
- LiquidCustomer, LiquidOrder, LiquidMerchandiseReturn host: kept as
  DomainHost? and replaced by the store URL when missing.
- DataSettingsManager.LoadDataSettings: null forgets the loaded
  settings, so the next read takes them from the file.
- PluginInfo constructor: a plugin that failed to load has no assembly
  or type; the properties were already nullable.
- Audit log List, HistoryPopup, HistoryList: query parameters a request
  may leave out, checked with IsNullOrEmpty.
- CustomerList searchCustomerTagIds: the store panel passes null to
  mean no tag filter.
- Knowledgebase PrepareKnowledgebaseNodeGridModel: null is the root,
  read as parentCategoryId ?? "".
- Merchandise return note: a note without an attached file binds the
  file as null; InsertMerchandiseReturnNoteCommand.File is no longer
  required and the handler already checks it.

No behaviour changes.
The 22 test projects compile with nullable enabled and nullable warnings
as errors. Nothing is suppressed; a test passes null! only where the
null exercises the guard of the code under test (a test about a missing
value), as for the production code.

How the tests changed:
- [TestInitialize] became the constructor (MSTest builds an instance per
  test), so the fields it sets are definitely assigned. An async
  initializer keeps only its awaits; a field that only an async start
  sets is nullable behind a property that throws until it is set.
- A value that may be null is asserted before use: Assert.IsNotNull
  before a dereference, Assert.IsInstanceOfType<T> for a cast of a
  view model or JSON value, First instead of FirstOrDefault where the
  test expects the element, x?.Y inside Assert.AreEqual.
- Moq setups of methods returning Task<T?> use ReturnsAsync, which
  takes T? from the method.
- A null passed where the parameter takes none became the neutral
  value of the type ("" , [], new()), or null! in a test about the
  missing value.
- Fields a Moq callback fills during the test are nullable.

Fixed on the way, in the tests only:
- PriceServiceTests set up the working currency before creating it, so
  the mock returned null; the currency is now created first.
- SeNameServiceTests (NUnit) runs an instance per test case, so its
  constructor replaces [SetUp].
The tests that came with #1132-#1142 compile under the same rules: [TestInitialize] became the constructor, a field a callback fills is nullable, and a test about a missing password passes null!.
Every project that imports Grand.Common.props now compiles with
Nullable enabled and nullable warnings as errors, so a new project or
plugin starts the same way. The per-project settings and the
#nullable enable directives are gone. The two Aspire projects do not
import the props and keep their own setting.
Copilot AI balanced review requested due to automatic review settings November 28, 2026 11:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

support added 3 commits November 28, 2026 12:46
… constructor

dotnet.md still said the plugins and tests were left out and that each project sets Nullable in its csproj; tests.md taught [TestInitialize], whose example no longer compiles now that test projects build with nullable warnings as errors.
…der nullable

Grand.Common.props appends nullable to WarningsAsErrors instead of replacing a value set before it. The admin configuration template declares ActiveStore as string?, as a plugin built from it otherwise fails with CS8618.
…omer

GetStateProvincesByCountryId returns an empty list for a missing or unknown country, so its signature no longer says it may return null and the callers drop their `?? []`.

DiscountRuleValidationRequest.Customer is required and not null, so the standard discount rules drop their `request.Customer == null` checks, and the test that passed a null customer is gone.
@grandnode-dev
grandnode-dev merged commit e4f3eab into develop Nov 29, 2026
9 checks passed
@grandnode-dev
grandnode-dev deleted the feature/nullable-plugins-tests branch November 29, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants