Skip to content

Conversation

ashish-naik
Copy link

@ashish-naik ashish-naik commented Sep 28, 2025

Issue Description

Response from websocket server does not include "__type":"Object" but PFDecoder expects this otherwise events failed to be caught.

Closes: Issue #1832

Approach

LiveryQuery server response sends data or events in "object":jsonf= format but PFDecoder.m checks for __type key which is missing as shown in below example so this fix will add "__type ":"Object" key-value if dictionary has className and objectId representing PFObject.

"object":{
"desc": "Technology",
"createdAt": "2020-10-03T19:34:16.823Z",
"updatedAt": "2025-09-27T17:55:02.360Z",
"image_name": "technology.png",
"className": "categories",
"objectId": "kHnBntWHHW"
},
"original": {
"desc": "Technologyy",
"createdAt": "2020-10-03T19:34:16.823Z",
"updatedAt": "2025-09-27T17:54:10.800Z",
"image_name": "technology.png",
"className": "categories",
"objectId": "kHnBntWHHW"
}

Requesting review.

  • Add tests - I am not able to run tests on local.
  • Add changes to documentation (guides, repository pages, in-code descriptions)

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of objects missing explicit type metadata to reduce failed parses and ensure data loads more reliably.
    • Adjusted LiveQuery delivery to avoid decoding failures that could interrupt real-time updates, improving update stability.
  • Refactor

    • Simplified internal decoding paths to increase consistency and maintainability without changing public APIs.

…ormat but PFDecoder.m checks for __type key which is missing as shown in below example so this fix will add "__type ":"Object" key-value if dictionary has className and objectId representing PFObject.

"object":{
    "desc": "Technology",
    "createdAt": "2020-10-03T19:34:16.823Z",
    "updatedAt": "2025-09-27T17:55:02.360Z",
    "image_name": "technology.png",
    "className": "categories",
    "objectId": "kHnBntWHHW"
},
"original": {
    "desc": "Technologyy",
    "createdAt": "2020-10-03T19:34:16.823Z",
    "updatedAt": "2025-09-27T17:54:10.800Z",
    "image_name": "technology.png",
    "className": "categories",
    "objectId": "kHnBntWHHW"
}
Copy link

🚀 Thanks for opening this pull request!

Copy link

coderabbitai bot commented Sep 28, 2025

📝 Walkthrough

Walkthrough

Injects "__type":"Object" into dictionaries missing __type when className and objectId exist so they follow the Object decoding path in PFDecoder. Separately, removes the live-query client path that decoded validated object dictionaries into a strongly-typed generic T and returned it.

Changes

Cohort / File(s) Summary
Decoder: Inject __type for objects
Parse/Parse/Source/PFDecoder.m
In decodeDictionary:, when __type is absent but both className and objectId are present, make a mutable copy, set __type = "Object", update the local type value, and continue through the existing Object-decoding branch. Other type branches and error handling unchanged.
LiveQuery: Remove typed object decoding
ParseLiveQuery/ParseLiveQuery/Internal/ClientPrivate.swift
Removed the code that decoded the validated object dictionary into a strongly-typed T via PFDecoder.object().decode(...) as? T and the associated error/return path; precondition checks for className and objectId remain.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller as Caller
  participant PFDecoder as PFDecoder.decodeDictionary
  participant ObjBranch as Object Branch
  participant PFObject as PFObject

  Caller->>PFDecoder: decodeDictionary(data)
  alt __type missing AND className & objectId present
    note right of PFDecoder #DDEBF7: Inject "__type":"Object" into mutable copy
    PFDecoder->>ObjBranch: route with type="Object"
  else __type present
    PFDecoder->>ObjBranch: route based on __type
  end
  ObjBranch->>PFDecoder: recursively decode remaining fields
  ObjBranch->>PFObject: construct with defaultClassName, objectId, data
  PFDecoder-->>Caller: decoded PFObject
Loading
sequenceDiagram
  autonumber
  participant Server as Server Event
  participant ClientBefore as LiveQuery Client (before)
  participant Decoder as PFDecoder.object()
  participant App as App Code

  Server-->>ClientBefore: object dictionary (className, objectId, fields)
  ClientBefore->>ClientBefore: validate className & objectId
  ClientBefore->>Decoder: decode(...) as T
  alt success
    ClientBefore-->>App: return T
  else failure
    ClientBefore-->>App: throw decoding error
  end
Loading
sequenceDiagram
  autonumber
  participant Server as Server Event
  participant ClientNow as LiveQuery Client (now)
  participant App as App Code

  Server-->>ClientNow: object dictionary (className, objectId, fields)
  ClientNow->>ClientNow: validate className & objectId
  note right of ClientNow #F7F3E8: Typed decoding step removed
  ClientNow-->>App: proceed without returning typed T here
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change of injecting the missing "__type" attribute for LiveQuery messages and clearly references the relevant context, making it immediately understandable to reviewers.
Description Check ✅ Passed The pull request description includes the vulnerability checklist, references the related issue, a clear issue description with example payload, an explicit "Closes" line, an approach section detailing the change logic, and pending TODOs for tests and documentation, covering all major template requirements despite missing one heading.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eeebc5b and 07b9c62.

📒 Files selected for processing (1)
  • Parse/Parse/Source/PFDecoder.m (1 hunks)
🔇 Additional comments (1)
Parse/Parse/Source/PFDecoder.m (1)

51-71: Guarded injection restores pointer semantics

The pointer-key scan keeps bare pointer stubs on the legacy path while still promoting enriched payloads to full objects. This addresses the regression concern cleanly.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Sep 28, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6cfad53 and eeebc5b.

📒 Files selected for processing (2)
  • Parse/Parse/Source/PFDecoder.m (1 hunks)
  • ParseLiveQuery/ParseLiveQuery/Internal/ClientPrivate.swift (0 hunks)
💤 Files with no reviewable changes (1)
  • ParseLiveQuery/ParseLiveQuery/Internal/ClientPrivate.swift

…nd on the presence of additional data fields so that bare pointer stubs continue to fall back to the legacy dictionary path.
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.

2 participants