Skip to content

Conversation

@G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented May 29, 2025

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 null when 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 mypy can understand so I've changed it to use isinstance.

(this is a smaller version of #56 which is focused on the impacted field that we're currently using)

Copy link
Collaborator

@Unifex Unifex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@G-Rath G-Rath merged commit add70f4 into main Jun 2, 2025
5 checks passed
@G-Rath G-Rath deleted the adjust-types branch June 2, 2025 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants