Skip to content

Including pointer in another pointer not working #849

Closed
@josephomills

Description

@josephomills

New Issue Checklist

Issue Description

I have an attendance system that has a Scan class, having a pointer to Gathering class that has a pointer to a GatheringType: I want to include the GatheringType field on the Gathering object when I query Scan class. I'm using the Flutter SDK to run a nested query. I get internal server error when I use includeObject or even excludeKeys on the inner query. This is my query method below:

static QueryBuilder<ScanObject> scanQuery(
      {required GatheringCategory category}) {
    final ParseUser user = getIt<AuthBloc>()
        .state
        .currentUserOption
        .getOrElse(() => ParseUser(null, null, null));

    // Get gathering type of given category
    final gatheringTypeQuery = QueryBuilder<GatheringTypeObject>(
        GatheringTypeObject())
      ..keysToReturn([GatheringTypeObject.kName, GatheringTypeObject.kCategory])
      ..whereEqualTo(GatheringTypeObject.kCategory, category.name.capitalize);

    // Get all gatherings of the given type
    final gatheringQuery = QueryBuilder<GatheringObject>(GatheringObject())
      ..includeObject([GatheringObject.kGatheringType])
      ..excludeKeys([GatheringObject.kExcluded])
      ..whereMatchesQuery(GatheringObject.kGatheringType, gatheringTypeQuery);

    // get all scans of the above gatherings
    final query = QueryBuilder<ScanObject>(ScanObject())
      ..includeObject([ScanObject.kGathering])
      ..orderByDescending(ScanObject.kScannedInAt)
      ..excludeKeys([ScanObject.kSelfie])
      ..whereEqualTo(ScanObject.kUser, user.toPointer())
      ..whereMatchesQuery(ScanObject.kGathering, gatheringQuery);

    return query;
  }

If I'm using the wrong approach, I'd be glad if I could be helped on that.

Steps to reproduce

Have 3 class A, B & C. Let B be a pointer in A & let C be a pointer in B. Then try and include an object of C in a query for object A like this:
queryForC
queryForB - whereMatchesQuery of queryC, includeObject C, (optionally exclude any key)
queryForA - whereMatchesQuery of queryForB, includeObject B

Run queryForA.

Actual Outcome

Problem is when I add includeObject or excludeKeys on the QueryBuilder for the inner query (queryForB), I get an internal server error. Without the inner includeObject, there's no error, but the GatheringType field on the Gathering object is null.

Expected Outcome

I'm expecting to get a success response with GatheringType object on each Gathering object from my Scan results.

Environment

Parse Flutter SDK

  • SDK version: 3.1.3
  • Operating system version: Windows 10

Server

  • Parse Server version: 4.5.0

Flutter

  • Flutter version: 3.3.9

Logs

I/flutter (17764): ParseLiveList: lazyLoading is on
I/flutter (17764): ╭-- Parse Request
I/flutter (17764): curl -X GET -H 'user-agent: Flutter Parse SDK 3.1.13' -H 'X-Parse-Application-Id: xxxxxxxxxxxxxxxxxxxx' -H 'X-Parse-Session-Token: r:948692d6fd9d2db69a60e8672832f667' -H 'X-Parse-Client-Key: xxxxxxxxxxxxxxxxxxxxxxx' https://parseapi.back4app.com/classes/Scan?where=%7B%22user%22:%20%7B%22__type%22:%22Pointer%22,%22className%22:%22_User%22,%22objectId%22:%226Mv2HlvU89%22%7D,%22gathering%22:%7B%22$inQuery%22:%7B%22where%22:%7B%22gatheringType%22:%7B%22$inQuery%22:%7B%22where%22:%7B%22category%22:%20%22Lecture%22%7D,%22className%22:%22GatheringType%22%22keys%22:name,category%7D%7D%7D,%22className%22:%22Gathering%22%22include%22:gatheringType,%22excludeKeys%22:excluded%7D%7D%7D&include=gathering&order=-scannedInAt&excludeKeys=selfie&keys=scannedInAt
I/flutter (17764):
I/flutter (17764):  https://parseapi.back4app.com/classes/Scan?where={"user": {"__type":"Pointer","className":"_User","objectId":"6Mv2HlvU89"},"gathering":{"$inQuery":{"where":{"gatheringType":{"$inQuery":{"where":{"category": "Lecture"},"className"
I/flutter (17764): ╰--
D/EGL_emulation(17764): app_time_stats: avg=9201.36ms min=9201.36ms max=9201.36ms count=1
D/EGL_emulation(17764): app_time_stats: avg=111.10ms min=29.73ms max=631.86ms count=9
I/flutter (17764): ╭-- Parse Response
I/flutter (17764): Class: Scan
I/flutter (17764): Function: ParseApiRQ.query
I/flutter (17764): Status Code: 1
I/flutter (17764): Type: InternalServerError
I/flutter (17764): Error: null
I/flutter (17764): ╰--
...
flutter (17764): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Unexpected character (at character 197)
E/flutter (17764): ...ecture"},"className":"GatheringType""keys":name,category}}},"className":...
E/flutter (17764):                                        ^
E/flutter (17764):
E/flutter (17764): #0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1383:5)
E/flutter (17764): #1      _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:836:49)
E/flutter (17764): #2      _parseJson (dart:convert-patch/convert_patch.dart:35:10)
E/flutter (17764): #3      JsonDecoder.convert (dart:convert/json.dart:612:36)
E/flutter (17764): #4      JsonCodec.decode (dart:convert/json.dart:216:41)
E/flutter (17764): #5      LiveQueryClient._subscribeLiveQuery
parse_live_query.dart:360
E/flutter (17764): #6      LiveQueryClient.subscribe
parse_live_query.dart:235
E/flutter (17764): <asynchronous suspension>

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions