Skip to content

DMS-1218: Fixed JSON quoting in localroles configuration#137

Open
chris-adam wants to merge 1 commit into
masterfrom
DMS-1218/fix-localroles-json-quoting
Open

DMS-1218: Fixed JSON quoting in localroles configuration#137
chris-adam wants to merge 1 commit into
masterfrom
DMS-1218/fix-localroles-json-quoting

Conversation

@chris-adam

@chris-adam chris-adam commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes task transition failures reported in SUP-54082: dexterity.localroles 2.0.0b0 switched the local-roles rel config parsing to strict json.loads without migrating legacy single-quoted data. Adds a 3.1.6 migration (Migrate_To_3_1.fix_localroles_json_quoting, called from the new Migrate_To_3_1_6) that normalizes every FTI's rel config from Python-repr to JSON (idempotent), registers the 3.1.5a → 3.1.6a upgrade step, and bumps the profile version to 3.1.6.

Ticket

DMS-1218 — https://support-imio.atlassian.net/browse/DMS-1218

Pre-PR checks

  • CHANGES up to date
  • Tests exist for new code (ignored: tests/test_migrations.py left untracked at author's request; passes locally 3/3)
  • Diff matches ticket
  • No debug leftovers
  • No stray files / secrets
  • Profile / version bumps (metadata.xml 3.1.4 → 3.1.6)
  • Commits reference ticket / mergeable

Commits

b92d813 DMS-1218: Fixed JSON quoting in localroles configuration

Summary by CodeRabbit

  • Bug Fixes
    • Fixed JSON quoting in the local roles configuration during upgrade to prevent mis-parsing and improve consistency.
  • New Features
    • Added the upgrade step to move instances to version 3.1.6a (from 3.1.5), ensuring a smooth path forward.
  • Chores
    • Updated the default profile metadata to version 3.1.6.
    • Added the fix entry to the changelog.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a 3.1.6 migration that normalizes malformed JSON quoting in localroles, registers the new upgrade step, updates the profile version, and records the change in the changelog.

Changes

3.1.6 Migration: localroles JSON quoting fix

Layer / File(s) Summary
fix_localroles_json_quoting implementation
imio/dms/mail/migrations/migrate_to_3_1.py
Adds ast and json imports; implements fix_localroles_json_quoting which scans portal type localroles, detects cfg["rel"] values that are not valid JSON, normalizes them via ast.literal_eval + json.dumps, marks localroles._p_changed, and logs errors or normalized type ids.
Migration wiring and version update
imio/dms/mail/migrations/migrate_to_3_1_6.py, imio/dms/mail/migrations/upgrades.zcml, imio/dms/mail/profiles/default/metadata.xml, CHANGES.rst
Introduces Migrate_To_3_1_6 with run_parts and migrate(context). Deactivates the 3.1.5a upgradeStep, registers a new 3.1.6a upgradeStep, bumps the profile version to 3.1.6, and adds the changelog note for DMS-1218.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, the quotes are in line,
localroles now parse just fine.
A migration hop from old to new,
with JSON fixed the rabbit way too!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing JSON quoting in localroles configuration.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch DMS-1218/fix-localroles-json-quoting

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@imio/dms/mail/migrations/migrate_to_3_1.py`:
- Around line 488-498: The localroles normalization in migrate_to_3_1 should not
silently continue after a bad rel value; instead, collect the failures in the
normalization loop around the ast.literal_eval/json.dumps handling and stop the
migration if any are found. Update the logic near the logger.error path so the
failure details are retained, then raise after processing (or otherwise prevent
finalization/version bump) so the upgrade cannot be marked successful when some
FTIs still have unnormalized rel data.

In `@imio/dms/mail/migrations/upgrades.zcml`:
- Around line 112-126: Keep the upgrade chain reachable from 3.1.4 in
upgradestep registration. The commented-out genericsetup:upgradeStep for
migrate_to_3_1_5 removes the only path from source="3.1.4", so either restore
that step or make the migrate_to_3_1_6 step start from the last shipped version
while keeping handler imio.dms.mail.migrations.migrate_to_3_1_5.migrate and
imio.dms.mail.migrations.migrate_to_3_1_6.migrate aligned with a valid
source-to-destination progression.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c164adcb-b81a-4180-ac34-b345de73e4de

📥 Commits

Reviewing files that changed from the base of the PR and between 1baa40e and b92d813.

📒 Files selected for processing (5)
  • CHANGES.rst
  • imio/dms/mail/migrations/migrate_to_3_1.py
  • imio/dms/mail/migrations/migrate_to_3_1_6.py
  • imio/dms/mail/migrations/upgrades.zcml
  • imio/dms/mail/profiles/default/metadata.xml

Comment on lines +488 to +498
try:
cfg["rel"] = json.dumps(ast.literal_eval(rel))
except (ValueError, SyntaxError):
logger.error("Cannot normalize rel %r on %s/%s/%s/%s",
rel, fti.getId(), keyname, state, principal)
continue
changed = True
if changed:
localroles._p_changed = True
fixed.append(fti.getId())
logger.info("Normalized localroles 'rel' on portal types: %s", fixed)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Abort the upgrade when a rel value cannot be normalized.

This path only logs the bad value and keeps going, so the upgrade can still finish and mark the profile as upgraded while some FTIs remain on the broken config that caused the transition failures in the first place. Please collect these failures and raise at the end (or otherwise stop finalization/version bump) so the migration cannot succeed partially.

🧰 Tools
🪛 ast-grep (0.44.0)

[info] 488-488: use jsonify instead of json.dumps for JSON output
Context: json.dumps(ast.literal_eval(rel))
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@imio/dms/mail/migrations/migrate_to_3_1.py` around lines 488 - 498, The
localroles normalization in migrate_to_3_1 should not silently continue after a
bad rel value; instead, collect the failures in the normalization loop around
the ast.literal_eval/json.dumps handling and stop the migration if any are
found. Update the logic near the logger.error path so the failure details are
retained, then raise after processing (or otherwise prevent finalization/version
bump) so the upgrade cannot be marked successful when some FTIs still have
unnormalized rel data.

Comment thread imio/dms/mail/migrations/upgrades.zcml
@chris-adam chris-adam requested a review from sgeulette June 29, 2026 10:21
@chris-adam chris-adam force-pushed the DMS-1218/fix-localroles-json-quoting branch from b92d813 to fc224fd Compare June 29, 2026 12:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
imio/dms/mail/migrations/upgrades.zcml (1)

112-125: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Restore a reachable upgrade chain to 3.1.6a.

Line 115 comments out the only source="3.1.4" step, and Line 123 registers the new migration from source="3.1.5" instead of 3.1.5a. That leaves existing portals on 3.1.4 with no forward step, and portals already upgraded to 3.1.5a will never match the new handler. Keep the 3.1.4 -> 3.1.5a step active and register this step from 3.1.5a, which also matches the PR’s stated migration contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@imio/dms/mail/migrations/upgrades.zcml` around lines 112 - 125, Restore the
upgrade chain in upgrades.zcml so portals can reach 3.1.6a from both 3.1.4 and
3.1.5a. Re-enable the existing genericsetup:upgradeStep for
migrate_to_3_1_5.migrate by removing the accidental comment marker, and change
the new genericsetup:upgradeStep for
imio.dms.mail.migrations.migrate_to_3_1_6.migrate to use source="3.1.5a" instead
of source="3.1.5". Keep the handler names and destination version unchanged so
the migration path stays reachable and consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@imio/dms/mail/migrations/upgrades.zcml`:
- Around line 112-125: Restore the upgrade chain in upgrades.zcml so portals can
reach 3.1.6a from both 3.1.4 and 3.1.5a. Re-enable the existing
genericsetup:upgradeStep for migrate_to_3_1_5.migrate by removing the accidental
comment marker, and change the new genericsetup:upgradeStep for
imio.dms.mail.migrations.migrate_to_3_1_6.migrate to use source="3.1.5a" instead
of source="3.1.5". Keep the handler names and destination version unchanged so
the migration path stays reachable and consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a5e67e16-4bf9-4c3f-8f83-f57d10e30eb2

📥 Commits

Reviewing files that changed from the base of the PR and between b92d813 and fc224fd.

📒 Files selected for processing (5)
  • CHANGES.rst
  • imio/dms/mail/migrations/migrate_to_3_1.py
  • imio/dms/mail/migrations/migrate_to_3_1_6.py
  • imio/dms/mail/migrations/upgrades.zcml
  • imio/dms/mail/profiles/default/metadata.xml
✅ Files skipped from review due to trivial changes (1)
  • CHANGES.rst
🚧 Files skipped from review as they are similar to previous changes (2)
  • imio/dms/mail/profiles/default/metadata.xml
  • imio/dms/mail/migrations/migrate_to_3_1_6.py

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.

1 participant