Repository navigation
fix(core): an optional context arg with no context takes its default - #769
Merged
Merged
Conversation
A class module taking a context arg den supplies is wrapped, and the wrapper advertised every other arg to the module system, including an optional entity-kind arg with no context here (home ? null on a host user). The module system then looked it up in _module.args and threw once it was read. Don't advertise those; their default applies. Reported in Matrix.
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.
Summary
Reported by @vipultyagi in Matrix: a class module that takes an optional context arg with no context in scope, next to one that is in scope, throws as soon as the absent one is read.
Their diagnosis was right. Taking a context arg that den has (
user) makeswrapFunctionModulewrap the module, and the wrapper advertised every arg it didn't supply itself to the module system, including the absent optionalhome. The module system then lookedhomeup in_module.args. Withhome ? nullalone the module isn't wrapped,stripEnrichmentArgsdrops the defaulted arg, and it works, which is why the single-arg form hid this. The same happens onnixos:{ user ? null, host ? null, ... }:on a host's own aspect throws onuser.Fix.
wrapFunctionModuledoesn't advertise an optional arg that names an entity kind and has no context here; it's den's to supply, and its default applies. Required ones still take the existing "requests '…' but no … context" path, and optional args that aren't entity kinds still reach the module system as in nixpkgs.Validation
New cells,
templates/ci/modules/deadbugs/optional-absent-context-arg.nix:home ? nullalone (control, passes on main too);home ? null, user ? null, the reported case;home ? null, user, config, the wrapper path that also passes module-system args;user ? null, host ? nullonnixos.The last three fail on main and pass here.
Full suite (
ci.bash, 4 workers): 2208/2208.