Closed cboulay closed 4 months ago
I think I was just mislead. In the following line,
Should it have been ez.Flag()
instead?
Actually, changing the problem-reproducing code to use ez.Flag()
raises a different error.
import json
import ezmsg.core as ez
from ezmsg.util.messagecodec import MessageEncoder, MessageDecoder
if __name__ == "__main__":
strmessage: str = json.dumps(ez.Flag(), cls=MessageEncoder)
obj = json.loads(strmessage, cls=MessageDecoder) # Raise TypeError
File "ezmsg/src/ezmsg/util/messagecodec.py", line 118, in object_hook
setattr(out_obj, TIMESTAMP_ATTR, timestamp)
File "<string>", line 4, in __setattr__
dataclasses.FrozenInstanceError: cannot assign to field '_log_timestamp'
I replaced the definition of Flag
with
@dataclass
class Flag:
"""Message with no contents"""
...
And this seems to work fine.
Thanks for addressing this; you fixed it in the now merged PR #53
I ran into this when trying to log-and-read ez.Flag messages.
TypeError: MessageMeta.__new__() missing 3 required positional arguments: 'name', 'bases', and 'classdict'
This is because the only 2 fields in
obj
areTYPE
andTIMESTAMP_ATTR
, so the finalobj
inout_obj = cls(**obj)
is an empty dict without the required arguments to instantiate aMessageMeta
obj. However, I highly doubt we want to instantiate aMessageMeta
; we'd probably want to instantiate aMessage
but this is deprecated anyway.