Skip to content

Conversation

@gasman
Copy link
Contributor

@gasman gasman commented Mar 25, 2025

Fix regression that appeared against Wagtail main following wagtail/wagtail@96f9ebe (https://github.com/wagtail/wagtail-localize/actions/runs/14027070555/job/39267538142).

TabHelper.field_edit_handler_mapping walks the tree of panels / edit handlers to build a lookup table based on field name. However, when it encountered an InlinePanel, it followed the panel_definitions attribute, whose members are taken directly from the model's panels definition and contain no reference to the corresponding model.

Prior to wagtail/wagtail@96f9ebe, wagtail-localize was able to call get_form_options on those unbound panel instances and get a result (and even a usable one, because it only cares about the widget item - although it could have got that directly from the panel's widget attribute instead of going through get_form_options). After this commit, get_form_options no longer works on unbound panel instances, because it looks at self.db_field, which is invalid without a model.

Fix this by updating TabHelper.field_edit_handler_mapping to follow child_edit_handler.children instead (which does correctly keep track of the model).

Fix regression that appeared against Wagtail main following wagtail/wagtail@96f9ebe (https://github.com/wagtail/wagtail-localize/actions/runs/14027070555/job/39267538142).

`TabHelper.field_edit_handler_mapping` walks the tree of panels / edit handlers to build a lookup table based on field name. However, when it encountered an InlinePanel, it followed the `panel_definitions` attribute, whose members are taken directly from the model's `panels` definition and contain no reference to the corresponding model.

Prior to wagtail/wagtail@96f9ebe, wagtail-localize was able to call `get_form_options` on those unbound panel instances and get a result (and even a usable one, because it only cares about the `widget` item - although it could have got that directly from the panel's `widget` attribute instead of going through `get_form_options`). After this commit, `get_form_options` no longer works on unbound panel instances, because it looks at self.db_field, which is invalid without a model.

Fix this by updating `TabHelper.field_edit_handler_mapping` to follow `child_edit_handler.children` instead (which does correctly keep track of the model).
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.13%. Comparing base (a0aa5b5) to head (4b371f8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #862   +/-   ##
=======================================
  Coverage   93.13%   93.13%           
=======================================
  Files          47       47           
  Lines        4241     4241           
  Branches      550      550           
=======================================
  Hits         3950     3950           
  Misses        174      174           
  Partials      117      117           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@zerolab zerolab left a comment

Choose a reason for hiding this comment

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

Makes sense. Thank you for taking the time

@zerolab zerolab merged commit 5cacf24 into wagtail:main Mar 25, 2025
12 checks passed
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