Skip to content

Conversation

@Kriskras99
Copy link
Contributor

This is a (failing) test for when the field order differs between the struct (Serde) and the schema:

The application panicked (crashed).
  assertion `left == right` failed
    left: Foo { a: "World", b: "Hello" }
   right: Foo { a: "Hello", b: "World" }
in avro/src/ser_schema.rs, line 2940
thread: ser_schema::tests::different_field_order_serde_vs_schema

There are two options:

  • Require that the field order is the same
  • Modify ser_schema.rs (and potentially de.rs) to care about the field order

@martin-g
Copy link
Member

martin-g commented Dec 5, 2025

Please fix the formatting issue.

@Kriskras99
Copy link
Contributor Author

Fixed, CI will still fail as the test does fail and we need to decide what the right course of action is.

@martin-g
Copy link
Member

martin-g commented Dec 5, 2025

we need to decide what the right course of action is

I won't have time to debug it in the next days but I was going to bet that we probably don't use the lookup map but we do -

.lookup
.get(key)

So, it must be something else.

@Kriskras99
Copy link
Contributor Author

The lookup is only used to find the field information from the name.
After that, the field is just written as there is no buffering for unordered fields.
I can write a fix for that, or we can decide that the Serde field order must match the Schema field order (and add that to the docs).

@Kriskras99 Kriskras99 changed the title test: Different field order between Serde and the Schema fix: Don't depend on Serde to provide fields in the right order Dec 7, 2025
@Kriskras99
Copy link
Contributor Author

I've added support for out-of-order fields in the serializer. In the deserializer no changed are necessary.
This changes test introduced in #227 as an #[avro(default = ...)] is now required when using any of the Serde skip attributes. I'm also working on a PR to check the Serde attributes in avro-derive (and add documentation for the attributes avro-derive supports as they don't seem to be documented anywhere).

@Kriskras99
Copy link
Contributor Author

I've downgraded it to a debug_assert and added an extra check in serialize_next_field so that it should never trigger it all.
I do think we should keep the debug_assert, because it has no performance impact but if the situation does happen it prevents data corruption.

I've also added a check that should prevent the debug_assert from
ever happening.
@Kriskras99
Copy link
Contributor Author

The match self.field_position.cmp(&field.position) was suggested by clippy, please let me know if you don't like it. Then I'll revert to if/else if/else and add an #[allow].

@martin-g martin-g added this to the 0.22.0 milestone Dec 8, 2025
@Kriskras99 Kriskras99 merged commit b7fa60d into main Dec 8, 2025
20 checks passed
@Kriskras99 Kriskras99 deleted the serde_ub branch December 8, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants