DRAW icon indicating copy to clipboard operation
DRAW copied to clipboard

TypeError when accessing "variants" property of "Submission" object

Open MrFrankenstein opened this issue 3 years ago • 2 comments

Got the following exception message while accessing variants property of a Submission object from my SubmissionPost class:

The following _TypeError was thrown building SubmissionPost(dirty):
type 'Null' is not a subtype of type 'String'
When the exception was thrown, this was the stack
#0      new SubmissionPreview._fromMap
package:draw/…/models/submission_impl.dart:491
#1      Submission.variants
package:draw/…/models/submission_impl.dart:254

Additionally, I have also found that this happens only when the variants field from the JSON object is not empty

MrFrankenstein avatar Sep 11 '21 06:09 MrFrankenstein

#216 fixes this. I no longer use DRAW so do any follow-up if required using a PR.

Firstly, DRAW is based on PRAW and from my knowledge PRAW no longer contains the thumbnail or variants fields. The reason is that these are provided dynamically and thus the only way to access them in PRAW now is by the using the raw object. As such i have no idea why this is even present in DRAW.

Secondly:

Additionally, I have also found that this happens only when the variants field from the JSON object is not empty

This is because the line causing the error is only called when a variant is present.

Thirdly, the cause of the error: From a quick look the code is trying to do this:

late String _id;

// later on
_id = map['id']; // this is a map containing all the variant data

Now the problem is that there is no id field in the JSON object. The only fields present are source and resolutions.

Temporary Fix: use the data field to manually get the object and parse it yourself OR until the PR that i provided gets merged, clone my branch preview-fix branch and use it instead.

SupremeDeity avatar Sep 19 '21 14:09 SupremeDeity

If thumbnail and variants aren't present anymore in Reddit's response, we should just remove them. Either way, thanks for submitting a PR, I'll take a look.

bkonyi avatar Sep 21 '21 16:09 bkonyi