Skip to content

Let metadata <expr> and stor insert/update record flags ignore pipeline input instead of erroring - #19254

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:fix_metadata_block_input
Oct 16, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:fix_metadata_block_input

Conversation

@fdncred

@fdncred fdncred commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

metadata with an argument fails when the call also has pipeline input:

[1] | each {|x| let s = (metadata $x).span; $s }
# Error: nu::shell::incompatible_parameters
#   pipeline input was provided / but a positional metadata expression was also given

The user never piped anything into metadata here. The first statement of a block receives the block's input, which is intended ("a" | do { let x = (str uppercase); $x } returns A), so metadata gets the closure's input along with $x and refuses. The same check rejects "a" | metadata $in, because $in stores the input in the variable and still passes it to the call.

The check came in with another PR. A command can't tell implicit block input from an explicit pipe at run time: both arrive as ordinary PipelineData in the same register.

This PR removes the check. When metadata gets an argument, the result describes only that argument: a record with its span. The input and its pipeline metadata are ignored. Before #16049 the argument's span was merged with the input's pipeline metadata, which attached the input's metadata to an unrelated value:

open Cargo.toml | metadata 5
# {span: ..., source: ".../Cargo.toml"}    <- input's source reported for the literal 5
ls | do { let m = (metadata $env.PWD); $m }
# {span: ..., path_columns: [name], ...}   <- ls's path columns reported for $env.PWD

stor insert --data-record and stor update --update-record had the same input-versus-argument check and failed the same way inside a block:

[{a: 1}] | each {|r| stor insert -t t -d $r }
# Error: Pipeline and Flag both being used

User-facing changes (Release notes)

metadata <expr> and stor insert/update record flags now ignore pipeline input instead of erroring

metadata <expression> now returns only the argument's span and ignores pipeline input instead of erroring. This allows calls such as [1] | each {|x| let s = (metadata $x).span; $s } and "a" | metadata $in to work even when they receive implicit block input or explicit pipeline input. Without an argument, metadata still reports the input's pipeline metadata.

stor insert --data-record and stor update --update-record likewise use the flag's record and ignore pipeline input instead of failing with "Pipeline and Flag both being used", allowing these calls to work inside blocks.

Additional notes

  • Since the input is ignored whenever an argument is given, an explicit pipe into these calls is now dropped without an error too (ls | metadata $x, ls | stor insert -t t -d {a: 1}). Erroring only on an explicit pipe would need the compiler to mark implicit block input, which no command can see today.
  • metadata $in returns only the span. The input's path_columns, content_type and custom keys are not included; use metadata without an argument for those. (source from open is already removed when the input is collected into $in.)

@fdncred
fdncred merged commit 776da6d into nushell:main Oct 16, 2026
12 checks passed
@fdncred
fdncred deleted the fix_metadata_block_input branch October 16, 2026 11:13
@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 16, 2026
@fdncred fdncred added A:pipeline-metadata Additional information passed along that is not directly attached to the values (e.g. LSCOLORS) notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:pipeline-metadata Additional information passed along that is not directly attached to the values (e.g. LSCOLORS) notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant