Skip to content

fix: Preserve user-supplied assertion names #1717

Closed

Description

@Jammy2211

Overview

Preserve user-supplied assertion names. Selected as one of four PyAutoFit model-inspection and test-reliability tasks authorized on 2026-10-25.

Plan

  • Reproduce the reported defect against current main.
  • Write the existing _name backing field in add_assertion; expose it on comparison and compound assertions without changing generic model names. Test named/default/chained assertions, violation messages and unchanged identifiers.
  • Run focused regressions and the full library suite; record any environmental or pre-existing failures honestly.

Tier: glance (notify for test-only task) — merge mode: human /prm; no merge requested.

Detailed implementation plan

Write the existing _name backing field in add_assertion; expose it on comparison and compound assertions without changing generic model names. Test named/default/chained assertions, violation messages and unchanged identifiers.

Repository: PyAutoFit; main clean at discovery; no existing active PyAutoFit claim or open PR found. Branch: feature/assertion-names. Each task retains a separate branch and PR. The four branches are coordinated within this user-authorized group, with no overlapping source edits committed together. Existing identifiers/output-directory identity must remain stable.

Original Prompt

add_assertion name is silently dropped

Type: bug
Target: PyAutoFit
Repos:

  • PyAutoFit
    Themes:
  • visualization
    Difficulty: small
    Autonomy: safe
    Priority: normal
    Status: formalised
    Consequence: glance
    Witness: model.add_assertion(model.sigma > 5.0, name="sigma_floor") then reading the assertion back reports name == "sigma_floor" instead of the default/None it reports today.
    Review-minutes: 3
    Unattended: ready
    Filed: 2026-09-10

add_assertion(..., name=...) accepts a name and then throws it away.

The assertion classes expose name as a read-only property, so the
constructor's assignment either no-ops or never happens; nothing is written to
the backing attribute. The fix is one line: write _name (the backing
field the property reads) rather than name.

Consequence: assertion labels are unusable. Anything that wants to display an
assertion — model.info, a log message, the model figure being designed under
the model-figures epic (draft/feature/autofit/model_figures_epic.md) — has
no human-readable handle for it and must fall back to reconstructing the
operands. Combined with the sibling defect that repr() of an assertion
recurses forever (draft/bug/autofit/assertion_repr_recurses_forever.md),
there is currently no safe way to print an assertion.

Add a test that sets a name through add_assertion and reads it back, and one
that checks the default when no name is given.

Found on 2026-09-10 by execution while auditing the PyAutoFit model API for the
model-figures design (research leg B, "What is missing from the PyAutoFit model
API", item 3).

Activity

  1. Jammy2211 commented on Oct 25, 2026

    @Jammy2211
    CollaboratorAuthor

    Shipped

    Merged in #1721 at 75124bb, unchanged from the reviewed head, following the user's /prm command. All workflow jobs at that head passed. Combined validation: 3913 passed, 1 skipped, 1 xfailed; identifier parity checked. Downstream workspace smoke was not run and remains an explicit validation limitation. Pending PyAutoFit release; no release performed.

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