Skip to content

Calculate Field counts selected rows the layer no longer has in its notices #2838

Not planned

Description

@jgregoriorincon

calculate_field (crates/engine/src/cmd/edit.rs:1597) passes every selected index to evaluate, including ones past the layer's end. Nothing is written to them (original.get(r) at edit.rs:1604), but losses.write counts them: they read as null, so a notice can say "is null in N rows" or list a division by zero for a row that doesn't exist, and {"rows": n} counts them too. Filtering the selection to existing rows fixes both; the rows answer would then change for callers (CLI, Python, MCP). The preview already skips such rows (#2822).

Activity

  1. jgregoriorincon commented on Nov 24, 2026

    @jgregoriorincon
    ContributorAuthor

    I'll take this one. Calculate Field will evaluate only the selected rows the layer still has, so its notices and its {"rows": n} answer count what it actually wrote, as edit.deleteFeatures already counts only existing rows in {"deleted": n}.

  2. jgregoriorincon commented on Nov 24, 2026

    @jgregoriorincon
    ContributorAuthor

    Closing this without a change: the state it describes can't arise in the app. Every path that changes a layer's rows or selection keeps the selection in range:

    • selecting filters to existing rows and normalizes (select.rs:153-168); loading a project or workspace normalizes too (project.rs:1792, workspace.rs:407);
    • deleting features takes the selection (edit.rs:705); edits that remove a row shift it (box_edit.rs:269, circle_edit.rs:207); edits that replace a layer's data clear it;
    • undo and redo swap the whole project, selection included (lib.rs:3679);
    • re-reading a source maps the selection by feature id (map/src/lib.rs:753, whole.rs:161).

    A selection with rows past the layer's end can only be made by setting it directly, so calculate_field's notices and its {"rows": n} answer count rows that exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions