Skip to content

feat!: Rework schema compatibility - #342

Merged
martin-g merged 5 commits into
mainfrom
schema_compatibility2
Jan 8, 2026
Merged

martin-g merged 5 commits into
mainfrom
schema_compatibility2

Conversation

@Kriskras99

@Kriskras99 Kriskras99 commented Nov 24, 2025 •

Copy link
Copy Markdown
Contributor

I think this is better overall, but I can understand if you would want to revert the Compatibility::Partial and keep exactly to old behavior.

This new implementation is (in my opinion) simpler than the previous iteration and easier to modify when needed.

I've introduced the concept of partial and full compatibility. Partial compatibility means that there incompatibilities but that depends on whats written, for example an enum [A, B, C] is partially compatible with the enum [A, B] but depends on what the writer has written.

Users wishing to be absolutely sure, can treat Compatibility::Partial as an error, others can use it to slowly upgrade from an old schema.

Depends on #339, should be rebased after that's merged

@martin-g

martin-g commented Dec 1, 2025

Copy link
Copy Markdown
Member

I'm afraid I cannot approve this PR :-/
I tried twice to review it but it is too big and there are API breaks which I think are not really necessary.

Partial compatibility means that there incompatibilities but that depends on whats written

How can one be sure what has been written with a given schema ? Anything that the schema accepts could be in the file. I cannot make assumptions that parts of the schema were never used.

If you strongly believe that it is better and it won't cause problems to the other users then feel free to merge it!

@Kriskras99

Copy link
Copy Markdown
Contributor Author

I'll remove the partial compatibility and do some more testing to compare the new version with the old version (I'll see if I can get a fuzzer to run).

@Kriskras99

Copy link
Copy Markdown
Contributor Author

I unfortunately couldn't get a fuzzer to work, the recursive branchy code makes it hard for the fuzzer to select new paths.

I took a look at Compatibility again, and I think it should stay. Here's a comparison of behaviour:

Writer Reader Old New
Union<Null, Int> Null Ok Partial
Union<Null, Int> Int Ok Partial
Null Union<Null, Int> Ok Partial
Int Union<Null, Int> Ok Partial
Union<Null, String> Union<Null, Int> Err Partial
Int TimeMicros Err Full
Enum<A, B, C> Enum<A, B, C, D> Ok Full
Enum<A, B, C> Enum<A, B> Err Partial

So the new behaviour allows slightly more, but is also more honest about the compatibility.
A user who wants absolutely no schema evolution errors, can check for Ok(Compatibility::Full), while a user who can allow that can just check is_ok.

What do you think based on this table?

@Kriskras99
Kriskras99 force-pushed the schema_compatibility2 branch 2 times, most recently from e1cf3bb to 4cf0087 Compare December 8, 2025 12:13
@Kriskras99
Kriskras99 changed the base branch from uuid to main December 8, 2025 12:14
@Kriskras99
Kriskras99 changed the base branch from main to uuid December 8, 2025 12:14
@Kriskras99
Kriskras99 changed the base branch from uuid to main December 8, 2025 12:14
@martin-g

martin-g commented Dec 8, 2025

Copy link
Copy Markdown
Member

The CI checks didn't run for this PR for some reason.
There are Clippy errors:

error[E0658]: `let` expressions in this position are unstable
   --> avro/src/schema_compatibility.rs:116:12
    |
116 |         if let Some(w_name) = writers_schema.name()
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

error[E0658]: `let` expressions in this position are unstable
   --> avro/src/schema_compatibility.rs:117:16
    |
117 |             && let Some(r_name) = readers_schema.name()
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

@Kriskras99

Kriskras99 commented Dec 8, 2025 •

Copy link
Copy Markdown
Contributor Author

Ah, that was made stable in 1.88. So shall we bump the MSRV or shall I rewrite it with a match statement?

Also the CI not running was me messing with target branch

@martin-g

martin-g commented Dec 8, 2025

Copy link
Copy Markdown
Member

Let's bump!
This will allow to update Darling too.

@martin-g martin-g added this to the 0.22.0 milestone Dec 8, 2025
@Kriskras99
Kriskras99 force-pushed the schema_compatibility2 branch from 41f11f4 to 521c723 Compare December 8, 2025 13:18
@Kriskras99

Copy link
Copy Markdown
Contributor Author

Version bumped and new lints fixed (some lints are gated behind the rust-version setting in Cargo.toml). If you agree with the table in #342 (comment) this can be merged.

Comment thread avro/src/error.rs Resolved
Comment thread avro/src/error.rs Resolved
Comment thread avro/src/schema_compatibility.rs Resolved
Comment thread avro/tests/serde_human_readable_true.rs Resolved
Comment thread avro/src/schema_compatibility.rs Resolved
Comment thread avro/src/types.rs Resolved
Comment thread avro/src/schema_equality.rs Resolved
Comment thread avro/src/schema_equality.rs Resolved
@Kriskras99
Kriskras99 force-pushed the schema_compatibility2 branch from 521c723 to 61b9a7c Compare December 8, 2025 14:33
@Kriskras99
Kriskras99 changed the base branch from main to uuid December 8, 2025 14:34
@Kriskras99
Kriskras99 force-pushed the schema_compatibility2 branch from 61b9a7c to 6d70a2a Compare December 18, 2025 09:56
@Kriskras99
Kriskras99 force-pushed the uuid branch 2 times, most recently from 86b4128 to 6a37335 Compare December 22, 2025 13:12
Base automatically changed from uuid to main December 22, 2025 14:40
Kriskras99 and others added 2 commits December 22, 2025 14:43
This new implementation is (in my opinion) simpler than the previous
iteration and easier to modify when needed.

I've introduced the concept of partial and full compatibility. Partial
compatibility means that there incompatiblities but that depends on whats
written, for example an enum `[A, B, C]` is partially compatible with
the enum `[A, B]` but depends on what the writer has written.

Users wishing to be absolutely sure, can treat `Compatibility::Partial`
as an error, others can use it to slowly upgrade from an old schema.
@Kriskras99
Kriskras99 force-pushed the schema_compatibility2 branch from 6d70a2a to 59189d6 Compare December 22, 2025 14:45
@Kriskras99
Kriskras99 force-pushed the schema_compatibility2 branch from 1cc27de to b51892b Compare December 22, 2025 15:06
@Kriskras99

Copy link
Copy Markdown
Contributor Author

Rebased on main, and test added for resolving Decimals with different inner types.

@Kriskras99
Kriskras99 requested a review from martin-g December 22, 2025 15:09
This adds support for the changed  `Schema::Duration(FixedSchema)`
@Kriskras99
Kriskras99 force-pushed the schema_compatibility2 branch from d63a6b0 to 25ca5ad Compare January 7, 2026 13:34
@Kriskras99

Copy link
Copy Markdown
Contributor Author

I've merged main to this branch and updated the code to work with the change in Schema::Decimal.

Anything left to do @martin-g?

Comment thread avro/src/types.rs Resolved
Comment thread avro/tests/shared.rs Resolved
Comment thread avro/src/schema_compatibility.rs Outdated
// float promotes to double
(Schema::Float, Schema::Float | Schema::Double) => Ok(Compatibility::Full),
(Schema::Double, Schema::Double) => Ok(Compatibility::Full),
// bytes and strings are interchangeable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the always interchangeable ?
UuidSchema::Bytes has to be exactly 16 bytes.
UuidString::String has to be at least 32 chars.
The checks for Decimal bytes schema also miss to check the precision and scale here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because they are decoded to and encoded from the uuid::Uuid type, resolving them will always work.
I've moved the Decimal check with the precision and scale above this statement, so this will only match now if one is Decimal::Bytes and one isn't.

@martin-g
martin-g merged commit e8a760d into main Jan 8, 2026
@Kriskras99
Kriskras99 deleted the schema_compatibility2 branch January 8, 2026 06:43
@Kriskras99 Kriskras99 mentioned this pull request Jun 28, 2026
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