Skip to content

fix: repair saved desktops not shown under "My Desktops" - #815

Closed
fstagni wants to merge 1 commit into
DIRACGrid:rel-v5r0from
fstagni:fix_desktop_state_roundtrip_v5r0
Closed

fstagni wants to merge 1 commit into
DIRACGrid:rel-v5r0from
fstagni:fix_desktop_state_roundtrip_v5r0

Conversation

@fstagni

@fstagni fstagni commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Cherry-pick of #814 for rel-v5r0 (same fix, applies cleanly - UPHandler.py is identical on both branches; #810/#811 equivalents are already in).

The v6.0.7 JSON migration broke the state save/load round trip in UPHandler:

 web_saveAppState(state)        # browser sends state as a JSON text (Ext.JSON.encode)
-  DEncode.encode(state)        # opaque wrap: decode + json.loads gave the structure back
+  json.dumps(state)            # double-encoded: JSON of a JSON string

 _safeDecode(raw)
-  json.loads(DEncode.decode(raw)[0])   # historic: str -> dict
+  DEncode.decode(raw)[0]               # regression: returns the JSON text as str

UP/listAppState therefore returned {name: "<json string>"} instead of {name: {...}}. In the frontend, oprVerifyDataStructure() throws on a string, the callback building the desktop tree never fires, and the "My Desktops" node is never created. Users with no saved desktops under the logged-in group still see the (empty) node - matching the reported symptom. Shared desktops kept working because their listing is metadata only. web_changeView was broken too (rejected every desktop with "Invalid desktop state format").

Changes:

  • web_saveAppState: store the state verbatim when it is already a JSON text
  • _safeDecode: unwrap redundant JSON string layers, restoring the historic json.loads(DEncode.decode(...)[0]) behavior. States saved with the broken versions decode correctly and self-heal on their next save - no DB migration needed
  • add regression tests covering all storage generations (legacy DEncode, double-encoded v6.0.7/8, current)

Evidence

  • Before: _safeDecode returned str for every stored desktop generation -> oprVerifyDataStructure() TypeError -> "My Desktops" missing
  • After: all three generations round-trip to the original dict:
legacy DEncode         -> dict ok=True
double-encoded v6.0.7  -> dict ok=True
current                -> dict ok=True

Note: the pytest run requires the DIRAC release matching this branch (rel-v5r0's WebHandler imports DIRAC.Core.Tornado.Server.TornadoREST, removed in newer DIRAC); the decode logic itself was verified against all storage generations.

Merge Danger

Door: two-way - pure backend decode/encode fix, no schema change, no data migration; stored data is untouched and self-heals on save.

Blast Radius: all users' saved desktops and application states (My/Shared Desktops, changeView). Shared-desktop metadata listing is unaffected.

The JSON migration (v6.0.7) broke the state save/load round trip: the
browser sends the state as an already serialized JSON text, so
json.dumps() in web_saveAppState double-encoded it, and _safeDecode()
returned the inner JSON string instead of the structure for both
double-encoded and legacy DEncode data. As a result UP/listAppState
returned strings, the frontend failed to build the 'My Desktops' tree
(TypeError in oprVerifyDataStructure), and web_changeView rejected
every desktop. Shared desktops kept working because their listing is
metadata only.

- store the state verbatim when it is already a JSON text
- unwrap redundant JSON string layers in _safeDecode, restoring the
  historic json.loads(DEncode.decode(...)[0]) behavior; data saved
  with the broken versions decodes correctly and self-heals on next
  save
- add regression tests covering all storage generations
@fstagni

fstagni commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Closing: the regression this fix addresses (introduced by the JSON-migration backport #811) was never released - v5.0.15 (49ee635) predates it, and no further v5r0 release is planned. The fix for the v6.0.x line is in #814 (integration).

@fstagni fstagni closed this Oct 29, 2026
@fstagni
fstagni deleted the fix_desktop_state_roundtrip_v5r0 branch October 29, 2026 08:26
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