Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

LiveQuery Not working with PFUser #56

Closed
mkaya93 opened this issue Aug 11, 2016 · 25 comments
Closed

LiveQuery Not working with PFUser #56

mkaya93 opened this issue Aug 11, 2016 · 25 comments

Comments

@mkaya93
Copy link

mkaya93 commented Aug 11, 2016

Hi,

I'm trying to use live query with pfuser. As shown on code.But I'm getting this error when I use PFUser in query.

let query = PFQuery(className: "Activity")
        query.whereKey("members", containedIn: [PFUser.currentUser()!])
        let subscription: Subscription<PFObject> = query.subscribe()
        subscription.handleEvent { (query, event) in
            print("event : \(event)")
        }

Error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (PFUser)'

@andrewjedi
Copy link

Having the same issue

@Samigos
Copy link

Samigos commented Sep 3, 2016

Same here! I think the above error applies to pointer-comparisons in general...

@andrewjedi
Copy link

andrewjedi commented Sep 3, 2016

I just decided to make another column with an array of strings of the objectId's for now, works great :)

@Samigos
Copy link

Samigos commented Sep 3, 2016

Good job, but still, the problem remains! Using objectIds isn't always possible.. Sometimes pointers are the only way to go...

@andrewjedi
Copy link

True, we need this fixed ! :(

@mkaya93
Copy link
Author

mkaya93 commented Sep 15, 2016

I opened this issue 1 month ago and no one from parse team didn't look and gave an answer. How we can fix it ?

@mmowris
Copy link

mmowris commented Sep 15, 2016

Can we get a bump on this? @richardjrossiii @nlutsenko

@kajensen
Copy link
Contributor

See #59, i'm sure you can do something nearly identical to allow pfobject pointers.

@mmowris
Copy link

mmowris commented Sep 15, 2016

@kajensen , as in the decode functionality like that PR does for geo?

@kajensen
Copy link
Contributor

Yeah just check if its a pfobject and create the dictionary with classname and id. Same thing can be done for nsdates. Not sure what would go into making subqueries and the more complex query parts work.

@mmowris
Copy link

mmowris commented Sep 15, 2016

@kajensen I'll look into that. So I theoretically could watch on the PFUser, but getting any relational data back for instance and working with that would prove to be more challenging?

@kajensen
Copy link
Contributor

kajensen commented Sep 15, 2016

Yeah, the issue is encoding the non-primitive data types. @richardjrossiii mentioned that the goal was to use the iOS sdk for such things but this is a quick workaround for the time being. I'm not sure of the progress (if any) on that front, i'll defer to the main contributors for that.

Encoding/decoding is the main issue with this library (from what I can tell). If people want to see this library useable (as do I), we're going to need to contribute and not just post "we want this fixed" or "how much longer til this gets fixed". As you can see its not super active nor ready for primetime.

@AnChiChang
Copy link

same issue

@flovilmart
Copy link
Contributor

@kajensen @AnChiChang have you checked at PR's #86 and #87 ? Doe they help?

@AnChiChang
Copy link

AnChiChang commented May 16, 2017

I had try this

    let query: PFQuery<Chat>  = Chat.query()!
        .whereKey("products", equalTo: aPFObject)
        .whereKey("togroupbuy", notEqualTo: true) as! PFQuery<Chat>    
    query.findObjectsInBackground {
        (objects, errors) in
        
        print("retrieved object = \(objects)")
        //print(errors)
    }
    
    
    self.subscription = liveQueryClient.subscribe(query).handleSubscribe {
        [weak self]  (_) in
        
        print("Subbed")
        }.handleEvent { [weak self] (_, event) in
            self?.handleEvent(event: event)
    }

or

    let query: PFQuery<Chat>  = Chat.query()!
        .whereKey("products", equalTo: PFObject(withoutDataWithClassName: "Products", objectId: aPFObject.objectId))
        .whereKey("togroupbuy", notEqualTo: true) as! PFQuery<Chat>
        
    query.findObjectsInBackground {
        (objects, errors) in
        
        print("retrieved object = \(objects)")
        //print(errors)
    }

get the same error message
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (PFObject)'

@AnChiChang
Copy link

Sorry, my fault. After update my ParseLiveQuery to 2.0. The problem is solved. Thanks for helping.

@flovilmart
Copy link
Contributor

All good then! Let's close that one!

@AnChiChang
Copy link

AnChiChang commented May 17, 2017

hello @flovilmart

I found a issue,
when I use where contained in a array of points. Still get
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (PFObject)'

can help ?

@flovilmart
Copy link
Contributor

Can you provide the logs or debugger dumps from the JSON responses?

@AnChiChang
Copy link

AnChiChang commented May 18, 2017

I am not sure which logs actually can help, just paste the dump information from xCode. If you need others, please let me know. Thanks.

        let query: PFQuery<ProductCount>  = ProductCount.query()!
            .whereKey("products", containedIn: findObjects) //findObjects is array of PFObject
            as! PFQuery<ProductCount>
        query.findObjectsInBackground {
            (objects, errors) in
            print("retrieved object = \(objects)")
        }
        
        self.subscription = liveQueryClient.subscribe(query).handleSubscribe {
            [weak self]  (_) in
            
            print("Subbed")
            }.handleEvent { [weak self] (_, event) in
                self?.handleEvent(event: event)
        }

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (PFObject)'
*** First throw call stack:
(
0 CoreFoundation 0x00000001102e3b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f933141 objc_exception_throw + 48
2 CoreFoundation 0x000000011034c625 +[NSException raise:format:] + 197
3 Foundation 0x000000010f42d2e2 _writeJSONValue + 679
4 Foundation 0x000000010f42d722 ___writeJSONArray_block_invoke + 130
5 CoreFoundation 0x000000011028ac31 __NSArrayEnumerate + 593
6 Foundation 0x000000010f42d423 _writeJSONArray + 317
7 Foundation 0x000000010f42d253 _writeJSONValue + 536
8 Foundation 0x000000010f481c4b ___writeJSONObject_block_invoke + 223
9 CoreFoundation 0x000000011026c25c __NSDictionaryEnumerate + 572
10 Foundation 0x000000010f481a42 _writeJSONObject + 394
11 Foundation 0x000000010f42d1c3 _writeJSONValue + 392
12 Foundation 0x000000010f481c4b ___writeJSONObject_block_invoke + 223
13 CoreFoundation 0x000000011026c25c __NSDictionaryEnumerate + 572
14 Foundation 0x000000010f481a42 _writeJSONObject + 394
15 Foundation 0x000000010f42d1c3 _writeJSONValue + 392
16 Foundation 0x000000010f481c4b ___writeJSONObject_block_invoke + 223
17 CoreFoundation 0x000000011026c25c __NSDictionaryEnumerate + 572
18 Foundation 0x000000010f481a42 _writeJSONObject + 394
19 Foundation 0x000000010f42d1c3 _writeJSONValue + 392
20 Foundation 0x000000010f481c4b __writeJSONObject_block_invoke + 223
21 CoreFoundation 0x000000011026c25c NSDictionaryEnumerate + 572
22 Foundation 0x000000010f481a42 writeJSONObject + 394
23 Foundation 0x000000010f42d1c3 writeJSONValue + 392
24 Foundation 0x000000010f42cfe7 -[NSJSONWriter dataWithRootObject:options:error:] + 124
25 Foundation 0x000000010f42cecc +[NSJSONSerialization dataWithJSONObject:options:error:] + 337
26 ParseLiveQuery 0x000000010eb738a0 TFFC14ParseLiveQuery6Client18sendOperationAsyncFOS_15ClientOperationGC10BoltsSwift4TaskT__U_FzT_T + 432
27 ParseLiveQuery 0x000000010eb75880 TPA__TFFC14ParseLiveQuery6Client18sendOperationAsyncFOS_15ClientOperationGC10BoltsSwift4TaskT__U_FzT_T + 224
28 ParseLiveQuery 0x000000010eb73d00 TTRXFo__zoPs5Error__XFo__iT_zoPS
+ 32
29 ParseLiveQuery 0x000000010eb75921 TPA__TTRXFo__zoPs5Error__XFo__iT_zoPS
.34 + 81
30 BoltsSwift 0x000000010e64bac7 TZFO10BoltsSwift9TaskState11fromClosurefFzT_xGS0_x + 87
31 BoltsSwift 0x000000010e64d6ed TFFC10BoltsSwift4TaskcFTOS_8Executor7closureFzT_x_GS0_x_U_FT_T + 125
32 BoltsSwift 0x000000010e6447d7 TTRXFo___XFdCb
+ 39
33 libdispatch.dylib 0x00000001146b44a6 _dispatch_call_block_and_release + 12
34 libdispatch.dylib 0x00000001146dd05c _dispatch_client_callout + 8
35 libdispatch.dylib 0x00000001146bb94f _dispatch_queue_serial_drain + 221
36 libdispatch.dylib 0x00000001146bc669 _dispatch_queue_invoke + 1084
37 libdispatch.dylib 0x00000001146bcb32 _dispatch_queue_override_invoke + 654
38 libdispatch.dylib 0x00000001146beec4 _dispatch_root_queue_drain + 634
39 libdispatch.dylib 0x00000001146bebef _dispatch_worker_thread3 + 123
40 libsystem_pthread.dylib 0x0000000114a74616 _pthread_wqthread + 1299
41 libsystem_pthread.dylib 0x0000000114a740f1 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

@AnChiChang
Copy link

I have saw someone can catch the JSON log, how to do that?

@flovilmart
Copy link
Contributor

run parse-server with VERBOSE=1

@AnChiChang
Copy link

verbose: Request: {"sessionToken":"","op":"connect","applicationId":"6gyO0FRa7kb6PjT6b5fum7f09Z2M85St"}
info: Create new client: 6
verbose: Push Response : "{"op":"connected","clientId":6}"

    let obj1 = PFObject(withoutDataWithClassName: "Products", objectId: "gN0cASy1e2")
    let obj2 = PFObject(withoutDataWithClassName: "Products", objectId: "mT7lpqscct")
    
    var objs: [PFObject] = [obj1, obj2]
    
    let remoteQ: PFQuery<ProductCount>  = ProductCount.query()!
        .whereKey("products", containedIn: objs)
        as! PFQuery<ProductCount>
    
    self.subscription = liveQueryClient.subscribe(remoteQ).handleSubscribe {
        [weak self]  (_) in
        
        print("Subbed")
        }.handleEvent { [weak self] (_, event) in
            self?.handleEvent(event: event)
    }

@AnChiChang
Copy link

AnChiChang commented May 18, 2017

Below will success subscribe:

verbose: REQUEST for [GET] /parse/classes/ProductCount: {
  "where": {
    "products": {
      "__type": "Pointer",
      "className": "Products",
      "objectId": "gN0cASy1e2"
    }
  }
} method=GET, url=/parse/classes/ProductCount, host=192.168.200.45:1111, x-parse-client-version=i1.14.2, accept=*/*, x-parse-application-id=appid, x-parse-client-key=clientkey, x-parse-installation-id=eda070f3-b50a-4eb8-ac91-cf0e2bec46a0, accept-language=en-us, x-parse-os-version=10.3 (16E195), accept-encoding=gzip, deflate, content-type=application/json; charset=utf-8, content-length=106, user-agent=livequerytest/1 CFNetwork/811.4.18 Darwin/16.5.0, connection=keep-alive, x-parse-app-build-version=1, x-parse-app-display-version=1.0, __type=Pointer, className=Products, objectId=gN0cASy1e2
verbose: RESPONSE from [GET] /parse/classes/ProductCount: {

Below will dump when subscribe:

verbose: REQUEST for [GET] /parse/classes/ProductCount: {
  "where": {
    "products": {
      "$in": [
        {
          "__type": "Pointer",
          "className": "Products",
          "objectId": "gN0cASy1e2"
        },
        {
          "__type": "Pointer",
          "className": "Products",
          "objectId": "mT7lpqscct"
        }
      ]
    }
  }
} method=GET, url=/parse/classes/ProductCount, host=192.168.200.45:1111, x-parse-client-version=i1.14.2, accept=*/*, x-parse-application-id=appid, x-parse-client-key=clientkey, x-parse-installation-id=eda070f3-b50a-4eb8-ac91-cf0e2bec46a0, accept-language=en-us, x-parse-os-version=10.3 (16E195), accept-encoding=gzip, deflate, content-type=application/json; charset=utf-8, content-length=184, user-agent=livequerytest/1 CFNetwork/811.4.18 Darwin/16.5.0, connection=keep-alive, x-parse-app-build-version=1, x-parse-app-display-version=1.0, $in=[__type=Pointer, className=Products, objectId=gN0cASy1e2, __type=Pointer, className=Products, objectId=mT7lpqscct]
verbose: Request: {"sessionToken":"","op":"connect","applicationId":"6gyO0FRa7kb6PjT6b5fum7f09Z2M85St"}
info: Create new client: 0
verbose: Push Response : "{\"op\":\"connected\",\"clientId\":0}"

@byroncoetsee
Copy link

So anyone struggling with this, my workaround has been:

extension PFObject {
    func pointer()->[String : Any] {
        guard self.objectId != nil else { return [:] }
        return [
            "__type" : "Pointer",
            "className" : self.parseClassName,
            "objectId" : self.objectId!
        ]
    }
}

Usage:
yourPFObject.pointer()

Can be used in LiveQuery.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants