fix: handle rich text field potentially being an empty list #60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So it turns out in some advisories some instances of this field are actually empty arrays which I think is because PHP uses associative arrays for what are "objects" in JavaScript,
dicts in Python, and hashes in Ruby. This means an empty associative array is the same as an empty indexed array, so when being turned into JSON PHP cannot know if it should be an actual array or an empty object so it goes with the former.While that sounds reasonable, what I'm unsure of is why Drupal would be returning an empty array rather than
nullwhen there isn't a value for an optional relationship - so this might actually be a bug on the upstreams end, but either way our types should represent the JSON we have today.The check we currently have for this field does guard against this, but technically does not narrow the type in a way that
mypycan understand so I've changed it to useisinstance.(this is a smaller version of #56 which is focused on the impacted field that we're currently using)