Closed thaije closed 3 years ago
I added a temp fix that double checks that the state in the api is a dict: https://github.com/matrx-software/matrx/commit/f5d1102cff34baa9de93d241653871eb219951c6 which I'll include with the new release.
@thaije I thought I had them all... There was an issue where the dictionary that State builds upon was also a State object. Which causes this issue. I thought I solved it, but perhaps I forgot something.
If this is the case, the State.to_dict()
will just return the thing State uses at its core, which will be just be another State instead of a dict. Causing the fix to fail just like when it was used when a State is added in the api.
For which type of agent does it happen and when (e.g., all the time or only when the agent perfoms an action)?
I might be able to look at it tonight.
It seems to occur only with the default human agentbrain (but not in Bw4T), and just opening the human agent view gives the error.
The error was cases because HumanAgentBrain
did not use State.state_update(state_dict)
appropriately (it passed a State
instance as state_dict
instead of an actual dict
). Fixed that and now State.state_update
throws an exception if it receives anything else then a dict
. If it receives a State
instance it will also suggest a fix: state.state_update(old_state.as_dict())
.
Describe the bug For some reason the new State object is not fully converted to a regular dict before the API tries to json serialize it, which in turn fails and throws the error (see stacktrace).
The weird thing is that converting the state to dict and reordering it is the first thing being done in the API when receiving an agent state, see here: https://github.com/matrx-software/matrx/blob/master/matrx/api/api.py#L970. Checking the type of the state here also confirms this works, however checking it for the human agent view of the
vis_test
case shows it as anState
object again here.To Reproduce Running the
vis_test
case, pressing play, and checking the human agent view gives the following error:TypeError: Object of type State is not JSON serializable
on this line in the API https://github.com/matrx-software/matrx/blob/dev/matrx/api/api.py#L141. It also happens for therun_test
case when opening the human agent view. However, it does not seem to happen for:Expected behavior No error and the state being converted to a dict in the API before it being sent to the frontend.
Stacktrace
Additional context Most likely a bug from fixing https://github.com/matrx-software/matrx/issues/202.