DRAW
DRAW copied to clipboard
TypeError when accessing "variants" property of "Submission" object
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
#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.
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.