Page MenuHomePhabricator

For now, restrict creation of Z883/Typed map instances to ones with Z6/Strings as the type of their keys
Closed, ResolvedPublic

Description

In native code, typed Maps (Z883) are deserialized to hash maps. There is no restriction in Wikifunctions on what types can serve as Map keys. This means that all deserialized ZObjects must be hashable.

In Python, this means that

  1. Typed Lists (Z881) should deserialize to Python tuples (instead of lists, as at present).
  2. Typed Maps (Z883) should deserialize to a custom extension of dict which is immutable and implements __hash__ and __eq__.
  3. The ZObject and ZPair classes (from function-evaluator::executors/python3/utils.py) must implement __hash__ (they already implement __eq__).

In JavaScript, we probably need to do something similar, but I don't know JS well enough to say extemporaneously what makes a good Map key 😿

Event Timeline

We discussed this being hard in the Engineering Check-In just now, and our provisional decision is that we will restrict to just strings for now. Trying to create a Map with non-string keys will instead throw an error. Thoughts?

Jdforrester-WMF renamed this task from Ensure All Deserialized ZObjects Can Function As Map Keys to For now, restrict creation of Z883/Typed map instances to ones with Z6/Strings as the type of their keys.Feb 17 2022, 5:45 PM
DMartin-WMF changed the task status from Open to In Progress.Feb 22 2022, 5:45 PM

Change 764935 had a related patch set uploaded (by David Martin; author: David Martin):

[mediawiki/services/function-orchestrator@master] Return error when Z983 called with non-string for key type

https://gerrit.wikimedia.org/r/764935

Change 764935 merged by jenkins-bot:

[mediawiki/services/function-orchestrator@master] Return error when Z983 called with non-string for key type

https://gerrit.wikimedia.org/r/764935