reflex.utils.exceptions.VarTypeError: Unsupported Operand type(s) for []: ObjectCastedVar, ObjectCastedVar
Describe the Features
Allow state dicts to be indexed by complex types (i.e., types other than string and int).
Example:
class Canonical_name(rx.Base):
prefix: str
name: str
postfix: str
class Variable(rx.Base):
canonical_name: Canonical_name
type: str
class Contract(rx.Base):
variables: dict[Canonical_name, Variable] = rx.field({})
This is currently disallowed in https://github.com/reflex-dev/reflex/blob/6c6201fbb016afc8d3236c262e8008952cf675e3/reflex/vars/object.py#L225
state variables have to be json serializable, so this cannot be supported (we're barely allowing it for numbers)
Maybe this could be supported with deterministic methods converting to string representation and parsing back, either implicit (generated) or explicitly implemented by the user? The latter would probably require duplicate implementation: for both the backend and the frontend.
javascript isn't well built for this :/ even equality doesn't work, so we cannot do much with this one