Skip to content

Fix control panel invariants failing on partial updates - #2072

Merged
davisagli merged 2 commits into
mainfrom
fix-controlpanel-invariants
Nov 1, 2026
Merged

davisagli merged 2 commits into
mainfrom
fix-controlpanel-invariants

Conversation

@sneridagh

@sneridagh sneridagh commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

A partial PATCH to @controlpanels/<name> fails with HTTP 500 when the control panel schema has an @invariant that reads a field the request omits:

TypeError: ('Could not adapt', <PloneSite at /plone>, <InterfaceClass ...>)

ControlpanelDeserializeFromJson validates invariants through z3c.form's IManagerValidator with only the submitted values and the portal as context. For omitted fields, z3c.form's Data wrapper tries to adapt the context to the schema, which fails for the portal.

Fix

Pass the registry proxy from registry.forInterface(...) as the validator's context. The proxy provides the schema, so invariants read the stored registry values for omitted fields. The response format is unchanged: one {"message", "error"} entry per invariant error, masked as ValidationError.

Tests

New test_controlpanel_deserializer.py, with a registry schema that has two optional Int fields and an invariant comparing them:

  • A partial update that satisfies the invariant keeps the stored value of the omitted field.
  • A partial update that violates the invariant against the stored values raises BadRequest with a single error.

Both tests fail with the TypeError above without the fix. The full suite passes locally (1429 tests).

Found while reviewing #2071, which has the same issue but keeps this fix out of scope.

Note for reviewers

#2071 adds a different src/plone/restapi/tests/test_controlpanel_deserializer.py, with tests for partial updates, unknown fields, field errors and invariants. Whichever PR merges second needs its tests merged into that file.

@mister-roboto

Copy link
Copy Markdown

@sneridagh thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@sneridagh
sneridagh requested a review from davisagli October 21, 2026 09:01
@davisagli

Copy link
Copy Markdown
Member

@jenkins-plone-org please run jobs

1 similar comment
@davisagli

Copy link
Copy Markdown
Member

@jenkins-plone-org please run jobs

@davisagli
davisagli changed the base branch from main to issue-2061-schema-helpers November 1, 2026 19:44
@davisagli
davisagli force-pushed the fix-controlpanel-invariants branch from 8ca23a8 to d7800c5 Compare November 1, 2026 19:54
Base automatically changed from issue-2061-schema-helpers to main November 1, 2026 20:06
Run the schema invariants with the registry proxy as context, so omitted
fields resolve to their stored values instead of failing to adapt the
portal to the schema.
@davisagli
davisagli force-pushed the fix-controlpanel-invariants branch from d7800c5 to 90091c6 Compare November 1, 2026 20:07
@davisagli
davisagli merged commit 61c3d6a into main Nov 1, 2026
16 of 20 checks passed
@davisagli
davisagli deleted the fix-controlpanel-invariants branch November 1, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants