You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not entirely sure why flatten does not work here but given how big of a hack it is, I'm not terribly surprised. For what it's worth the issue here is unlikely to be context! which is just syntax support for creating a Value holding a map. You can probably repro this also this way:
So the issue here is more or less the following: a Value when serialized for internal usage turns into a struct (we use in-band signalling here: serde-rs/serde#1463) which is later picked up again. That struct looks something like this:
\x01__minijinja_ValueHandle{handle: i64
}
The handle is a reference to an internal counter of the value, which is then picked up from a thread local stashed away slot. When serde(flatten) comes in, it detects that handle and inlines it. This means that this:
I changed the serialization format to an enum for testing purposes, but then the end result looks like this:
error: can only flatten structs and maps (got an enum)
In some sense it would be necessary to detect that flattening is requested, and to then dump out the structural form of the value rather than the reference. There is currently no way to detect this as serde does not communicate to the serialization interface that flattening is requested. This relates to this issue in some sense: serde-rs/serde#1183
Description
minijinja::context!
and#[serde(flatten)]
sometimes don't work correctly together.Reproduction steps
cargo run
and observe the outputAdditional helpful information:
What did you expect
I was expecting
minijinja::context!
to be equal toserde_json::json!
The text was updated successfully, but these errors were encountered: