#19110·nushell

`flatten --all` (no column) still drops a value when an inner-table field collides with a later top-level column

Author: Master-NornaCreated Sep 29, 2026Updated Sep 29, 2026

Bug report form

  • I have done a basic search of the issue tracker to find any existing issues that are similar.
  • I have checked that my version is at least the latest stable release available via my installation method.

Describe the bug

flatten --all with no column arguments (the default/common invocation) still produces a duplicate column and loses a value when an inner table's field has the same name as a top-level column that appears after the inner table. This is the same class of bug as #13271, but the no-column inner-table path was never covered by the fixes.

nushell
# inner-table column `b` first, top-level colliding column `a` second, NO column args:
[[b, a]; [[[a]; [9]], 1]] | flatten --all | to nuon
#   [{a: 9, a: 1}]          # duplicate `a`; `get a` returns 1, so the inner 9 is lost

# controls — these already work:
[[b, a]; [[[a]; [9]], 1]] | flatten --all b | to nuon   # [[b_a, a]; [9, 1]]  (explicit column)
{b: {a: 9}, a: 1} | flatten --all | to nuon             # [[b_a, a]; [9, 1]]  (nested record)
[[a, b]; [1, [[a]; [9]]]] | flatten --all | to nuon     # [[a, b_a]; [1, 9]]  (top col before inner)

So the rename works when a column is named explicitly, when the value is a nested record, and when the colliding top-level column comes before the inner table — but not for the plain flatten --all over an inner table with the colliding column after it.

Bug history (why this is a residual, not a new bug)

  • #13271 (2024-06, closed 2026-06-18): "flatten does not rename conflicting column if parent's conflicting column appears after the column to be flattened". Repro used flatten -a b (explicit column).
  • PR #18407 (merged, closed #13271): added the order-independent out.contains_key(col) check to the inner-table guard, but gated it behind !columns.is_empty() — so it only fires when a column is named.
  • PR #19059 (2026-09): made the nested-record path order-independent (computes retained outer columns unconditionally), but did not touch the inner-table path.

Net result: the explicit-column case and the nested-record case are fixed; the no-column inner-table case (the default flatten --all) is still order-dependent.

Root cause

In crates/nu-command/src/filters/flatten.rs, the inner-table (FlattenedRows) branch's collision guard is record.contains(col) || (!columns.is_empty() && out.contains_key(col)). With no column args, columns.is_empty() is true, so the order-independent second disjunct is disabled, and record.contains(col) is only true if the colliding column was already pushed earlier. When it isn't, the inner field is pushed under its bare name and then the top-level column is pushed under the same bare name → duplicate keys (see Record::push, crates/nu-protocol/src/value/record.rs, "naive push … may duplicate data"). The nested-record branch uses the order-independent retained_outer_columns and does not have this problem.

Expected behavior

flatten --all should rename the colliding inner field to b_a regardless of column order, matching the explicit-column and nested-record paths: [[b_a, a]; [9, 1]].

Configuration

Reproduces on main (0.116.0, 2459fdd).


Reported via an AI-assisted audit; the reproduction and code trace were verified against a local build.