Skip to content

Conversation

@Tschuppi81
Copy link
Contributor

@Tschuppi81 Tschuppi81 commented Dec 16, 2025

Directory: Fix directory migration crash when renaming option labels

TYPE: Bugfix
LINK: ogc-2353

@linear
Copy link

linear bot commented Dec 16, 2025

@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

❌ Patch coverage is 96.62921% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.42%. Comparing base (15569d6) to head (6c428e4).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/onegov/directory/migration.py 97.36% 2 Missing ⚠️
src/onegov/org/views/directory.py 92.30% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/onegov/org/views/directory.py 81.60% <92.30%> (+1.60%) ⬆️
src/onegov/directory/migration.py 97.78% <97.36%> (+5.24%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 15569d6...6c428e4. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Tschuppi81 Tschuppi81 requested a review from Daverball December 18, 2025 08:37
Copy link
Member

@Daverball Daverball left a comment

Choose a reason for hiding this comment

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

This looks like a decent start, but we need to allow more operations than renaming a single option, there's many other legal changes, that will not result in form validation errors on existing entries.

@Tschuppi81 Tschuppi81 requested a review from Daverball January 8, 2026 06:50
Copy link
Member

@Daverball Daverball left a comment

Choose a reason for hiding this comment

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

Looks pretty good. We're getting close, but I think we're now being a bit to laissez-faire with renaming options.

Comment on lines +185 to +192
def remove_old_options(self, values: dict[str, Any]) -> None:
for human_id, label in self.changes.removed_options:
id = as_internal_id(human_id)
if id in values:
if isinstance(values[id], list):
values[id] = [v for v in values[id] if v != label]
elif values[id] == label:
values[id] = None
Copy link
Member

Choose a reason for hiding this comment

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

It seems slightly controversial to delete existing selections. We might want to add an additional warning/confirmation step, if we detect that removing/renaming an option would modify the recorded data of existing entries (it would always be fine if none of the existing entries have selected this option).

Copy link
Contributor Author

@Tschuppi81 Tschuppi81 Jan 12, 2026

Choose a reason for hiding this comment

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

It is actually the same as with removing fields.
This is what you currently need to confirm:
image

Is that what you meant (A) or do you think of an extra step (B) where each entry would need to be changed in a separate window before an option can be removed?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, although it might be nice to be a bit more explicit that some data will be lost if there are existing entries that use the removed option.

Tschuppi81 and others added 3 commits January 8, 2026 02:32
Co-authored-by: David Salvisberg <david.salvisberg@seantis.ch>
form.populate_obj(self.directory)

try:
form.populate_obj(self.directory)
Copy link
Member

Choose a reason for hiding this comment

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

Are we doing a good enough job of visualizing the ValidationError that can be emitted by Directory.update as part of DirectoryMigration.execute? E.g. when we add a required field to a directory with existing entries, are we getting a better error than "Eingabe erforderlich", do we see which field caused the issue? It might be worth detecting this common mistake, to provide a better error message, since you can never add a required field (other than a checkbox/radio field with a pre-selected option) to a directory that already has some entries, you will always need to make it optional first, fill in the field for all existing entries and then update the field to be required.

Copy link
Contributor Author

@Tschuppi81 Tschuppi81 Jan 13, 2026

Choose a reason for hiding this comment

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

The ValidationError pops up saying which field is required. But when opening the link to the entry the new field does not exist yet so we end up in a deadlock.
I will detect this mistake and through an error to the user preventing required fields in one step

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.

3 participants