Skip to content

fix(backchecks): apply the duplicate option and target % from settings - #317

Open
iabaako wants to merge 3 commits into
feat/298-outlier-constraint-correctionsfrom
fix/299-backcheck-settings-fields
Open

iabaako wants to merge 3 commits into
feat/298-outlier-constraint-correctionsfrom
fix/299-backcheck-settings-fields

Conversation

@iabaako

@iabaako iabaako commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Summary 🚀

What does this PR do? 📝

Makes the backcheck duplicate-handling option and target % chosen in the settings panel actually take effect. Closes #299.

 backchecks_report_settings
   return BackcheckSettings(
-    backcheck_goal=...,            # not a model field → silently dropped
-    drop_duplicates=...,           # not a model field → silently dropped
+    backcheck_target_percent=...,
+    drop_duplicates_option=...,    # read by compute_backcheck_analysis
   )

 _render_tracking_options
-  save_check_settings(..., {"backcheck_goal": ...})            # never reloaded
+  save_check_settings(..., {"backcheck_target_percent": ...})  # reloads next session

Why is this change needed? 🤔

BackcheckSettings ignores unknown keywords, so both values fell back to their defaults:

  • Duplicate IDs were always dropped, whatever the user selected.
  • The target was always 10, whatever the input said.

How was this implemented? 🛠️

  • Pass the model's field names in backchecks_report_settings.
  • Save the target under backcheck_target_percent so load_default_backchecks_settings reloads it. Targets saved under the old backcheck_goal key were never applied and are now ignored (noted in the CHANGELOG).
  • Rename the backcheck_goal local to backcheck_target_percent so it matches the field it feeds.

Not done: extra="forbid" on BackcheckSettings (suggested in the issue). The model is also built from dicts that legitimately carry extra keys, so forbid would raise errors:

  • the saved backchecks-tab settings (string_case_option, enum_bcer_stats_view, …) merged in load_default_backchecks_settings
  • backchecker_team from output_view_template.py, passed to BackcheckSettings(**config) in report_ui.py

Follow-ups found during review (out of scope, planned in #318):

#318 (7 of 13 in the stack, after #300) redesigns the backcheck target metrics and covers all three:

How to test or reproduce ? 🧪

uv run python -m pytest tests/checks/backchecks/test_settings_ui.py
just test

New tests in tests/checks/backchecks/test_settings_ui.py:

Test Before After
test_report_settings_keeps_selected_duplicate_option ❌ 'drop' == 'last' ✅
test_report_settings_keeps_selected_target_percent ❌ 10 == 35 ✅
test_render_tracking_options_saves_under_model_field_name ❌ saved {'backcheck_goal': 35} ✅

Full suite: 3511 passed, 6 skipped. Existing test_compute.py tests already cover how first / last / drop change the results.

Manual: in a backchecks page, choose Keep Last Entry and set a non-default target. Duplicates are now kept rather than dropped, and the target persists after a reload.

Merge risk: low and easy to undo (revert the commits). It affects only the backcheck report: projects whose saved settings say first or last will now keep duplicate IDs instead of dropping them, which changes the backcheck counts users see.

Screenshots (if applicable) 📷

N/A. The settings panel looks the same; only the values passed through it change.

Checklist ✅

  • I have run and tested my changes locally
  • I have limit this PR to less than 1000 lines of code change (if not, explain why)
  • I have updated/added tests to cover my changes (if applicable)
  • I have updated/added requirements to cover my changes (if applicable): N/A, no new dependencies
  • I have run linting and formatting on any code changes (if applicable)
  • I have updated the documentation (README, etc.) accordingly: CHANGELOG entry under Fixed
  • I have reviewed and resolved any merge conflict

Reviewer Emoji Legend

:code: Meaning
😃👍💯 :smiley: :+1: :100: I like this...

...and I want the author to know it! This is a way to highlight positive parts of a code review.
⭐⭐⭐ :star: :star: :star: Important to fix before PR can be approved...

And I am providing reasons why it needs to be addressed as well as suggested improvements.
⭐⭐ :star: :star: Important to fix but non-blocking for PR approval...

And I am providing suggestions where it could be improved either in this PR or later.
⭐ :star: Give this some thought but non-blocking for PR approval...

...and consider this a suggestion, not a requirement.
❓ :question: I have a question.

This should be a fully formed question with sufficient information and context that requires a response.
📝 :memo: This is an explanatory note, fun fact, or relevant commentary that does not require any action.
⛏ :pick: This is a nitpick.

This does not require any changes and is often better left unsaid. This may include stylistic, formatting, or organization suggestions and should likely be prevented/enforced by linting if they really matter
♻️ :recycle: Suggestion for refactoring.

Should include enough context to be actionable and not be considered a nitpick.

🤖 Generated with Claude Code

iabaako and others added 2 commits October 3, 2026 19:37
backchecks_report_settings passed `drop_duplicates` and `backcheck_goal`,
which BackcheckSettings silently ignored, so duplicates were always dropped
and the target was always 10. Use the model field names, and save the target
under `backcheck_target_percent` so it reloads.

Closes #299

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rename `backcheck_goal` to `backcheck_target_percent` so the local matches
the BackcheckSettings field it feeds, and note in the changelog that targets
saved under the old key are ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iabaako
iabaako requested a review from a team as a code owner October 3, 2026 18:48
@iabaako iabaako linked an issue Oct 3, 2026 that may be closed by this pull request
2 tasks
@iabaako
iabaako added this pull request to stack #313 October 3, 2026 18:55
@iabaako
iabaako requested a balanced review from Copilot October 4, 2026 07:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The target cannot persist because its save callback still activates the old session-state key.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes backcheck settings field mapping so duplicate handling and target percentages reach BackcheckSettings.

Changes:

  • Uses the correct model field names.
  • Persists the target under its model field name.
  • Adds regression tests and changelog documentation.
File Description
src/​datasure/​checks/​backchecks/​settings_ui.py Corrects settings mapping and persistence key.
tests/​checks/​backchecks/​test_settings_ui.py Tests non-default setting propagation.
CHANGELOG.md Documents the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/datasure/checks/backchecks/settings_ui.py Outdated
save_check_settings only writes when `backchecks_<key>` is set in session
state. The key is now `backcheck_target_percent`, but the widget callback
still set `backchecks_backcheck_goal`, so the target was never saved. Test
the round trip through the real save guard instead of mocking the save.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Oct 4, 2026

Copy link
Copy Markdown

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backcheck duplicate-handling option and target % are silently ignored

2 participants