Skip to content

fix(types): Serialize BadRequest::FieldViolation reason and localized_message - #2461

Merged
LucioFranco merged 3 commits into
grpc:masterfrom
MathieuTricoire:field-violation-serialization-fix
Sep 16, 2026
Merged

LucioFranco merged 3 commits into
grpc:masterfrom
MathieuTricoire:field-violation-serialization-fix

Conversation

@MathieuTricoire

@MathieuTricoire MathieuTricoire commented Dec 5, 2025 •

Copy link
Copy Markdown
Contributor

Motivation

fix #2460

Fields reason and localized_message from BadRequest::FieldViolation are not serialized into the underlying protobuf message and therefore never make it onto the wire.

Solution

Fix the conversion from FieldViolation to the prost-generated pb::bad_request::FieldViolation by explicitly forwarding both the reason and localized_message fields instead of leaving them at their default values.

A new test is added to ensure that behavior.

}

#[test]
fn gen_bad_request_with_verbose_field_violation() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd recommend either merging the business logic into the original test or creating an incremental fine grained test that tests just the new business logic that has been added in this change.

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.

Thanks @sauravzg for the review! I've merged the new coverage into the original test as suggested. Let me know if this looks good to you.

@MathieuTricoire

Copy link
Copy Markdown
Contributor Author

Hi! Just checking in, it looks like a new release went out without the fix. Any chance it could be merged soon?

@MathieuTricoire

Copy link
Copy Markdown
Contributor Author

@sauravzg Sorry to ask again but is there any chance it could be merged?

@sauravzg

Copy link
Copy Markdown
Contributor

@LucioFranco LGTM from my side. Please see if this looks okay and merge.

@MathieuTricoire
MathieuTricoire force-pushed the field-violation-serialization-fix branch from 0d75d59 to c3f0aa0 Compare March 31, 2026 16:03
@MathieuTricoire

MathieuTricoire commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor Author

@LucioFranco @sauravzg I rebased on top of the latest main, would appreciate a fresh approval if needed (no changes from last approval) 🙏

@MathieuTricoire
MathieuTricoire force-pushed the field-violation-serialization-fix branch from 8ab953d to 13c2146 Compare July 11, 2026 13:58
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@MathieuTricoire
MathieuTricoire changed the base branch from v0.14.x to master July 11, 2026 14:11
@MathieuTricoire

Copy link
Copy Markdown
Contributor Author

Hi @sauravzg
I rebased onto master and retargeted the PR there since v0.14.x seems stale, let me know if that's correct.
The diff is unchanged from what you approved: one file (bad_request.rs)
Could it be picked up for the next tonic patch release?

@MathieuTricoire

Copy link
Copy Markdown
Contributor Author

Hi, sorry again but I'm not sure who I need to ping here, is there still any interest in merging this fix?

It's been almost 8 months since I opened the PR, it was approved back in December, and I've rebased it a couple of times since then without much progress.

If there's no interest in merging it, that's genuinely completely fine to me, but I'd rather know so I can close the PR (noise for the project and you) and stop maintaining / tracking it (noise for me).

@dfawley @arjan-bal @ejona86 @YutaoMa @nathanielford @gu0keno0

@dfawley dfawley left a comment

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.

Any idea why these fields weren't getting propagated before? That would take some spelunking through the commit history. Were they omitted on purpose? Were the fields added later?

This does look good to me in theory, but I don't know much about these types.

pb::bad_request::FieldViolation {
field: value.field,
description: value.description,
..Default::default()

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.

We should keep the ..Default::default() in case the proto message is extended in the future.

But also if that happens, I'm not sure what that means for the FieldViolation struct here, but that's a totally separate issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FWIW Default::default() defaults anything in the receiving struct but not passed explicitly. And in this case, reason and localized_message were late additions to the FieldViolation proto and just never added into the serialization code. It was added to the deserialization code. So it's just been dropping these fields when being serialized.

I did a brief search and I think this is the only place where this oversight happened.

If FieldViolation is extended in the future, extra fields will still be dropped by this serialization if we keep the default call. I think we would need to remove it if we want to use compilation failure to force an update here. I don't think this has any impacts on in-production systems, so I might advocate for that.

@MathieuTricoire

Copy link
Copy Markdown
Contributor Author

No idea why, but I suppose it was just a simple oversight.

If I remember correctly, I had opened #2244 about these new fields some time ago and proposed an initial solution. It wasn't perfect since it introduced breaking changes, but it was meant as a starting point: MathieuTricoire@86d1095

In the meantime a PR about these new fields landed and seems to be where this oversight was introduced: #2306

I think it's ultimately a project-level design decision regarding ..Default::default(). The question is whether future fields should be tolerated and defaulted, or deliberately cause a compilation failure until the conversion is updated.

So I can keep it, let me know.

@dfawley

dfawley commented Jul 27, 2026

Copy link
Copy Markdown
Member

I think it's ultimately a project-level design decision regarding ..Default::default(). The question is whether future fields should be tolerated and defaulted, or deliberately cause a compilation failure until the conversion is updated.

Adding fields to a proto message should be a backward-compatible operation. That said, this crate owns its own protobuf code generation, as opposed to an external dependency, so either way is valid here. I'd rather let @LucioFranco weigh in his opinion on it.

@LucioFranco
LucioFranco merged commit bdd3f14 into grpc:master Sep 16, 2026
25 checks passed
@github-actions github-actions Bot mentioned this pull request Sep 16, 2026
LucioFranco pushed a commit that referenced this pull request Oct 27, 2026
## 🤖 New release

* `tonic`: 0.14.6 -> 0.14.7 (✓ API compatible changes)
* `tonic-build`: 0.14.6 -> 0.14.7 (✓ API compatible changes)
* `tonic-prost`: 0.14.6 -> 0.14.7 (✓ API compatible changes)
* `tonic-health`: 0.14.6 -> 0.14.7 (✓ API compatible changes)
* `tonic-types`: 0.14.6 -> 0.14.7 (✓ API compatible changes)
* `tonic-reflection`: 0.14.6 -> 0.14.7 (✓ API compatible changes)
* `tonic-prost-build`: 0.14.6 -> 0.14.7 (✓ API compatible changes)
* `tonic-web`: 0.14.6 -> 0.14.7 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

## `tonic`

<blockquote>

##
[0.14.7](tonic-v0.14.6...tonic-v0.14.7)
- 2026-10-26

### Fixed

- *(codec)* eliminate uninitialized memory in encode_item on unwind
([#2847](#2847))
- *(transport)* drop listener before draining connections
([#2824](#2824))
- fix/silence all clippy warnings
([#2807](#2807))
- *(status)* map h2 FRAME_SIZE_ERROR to Code::Internal
([#2641](#2641))
- *(codec)* respect server's enabled encodings when selecting response
compression ([#2655](#2655))

### Other

- *(deps)* require patched zstd
([#2962](#2962))
- fix changelog duplicate and update repository URLs
([#2943](#2943))
- *(deps)* require patched rustls-webpki and webpki-roots
([#2940](#2940))
- handle ipv6 endpoints when tls is enabled
([#2423](#2423))
- support immediate cancellation of streams without sending
End-of-Stream ([#2791](#2791))
- wrap connection_timeout in Fuse to prevent panic
([#2780](#2780))
- License update ([#2749](#2749))
</blockquote>

## `tonic-build`

<blockquote>

##
[0.14.7](tonic-build-v0.14.6...tonic-build-v0.14.7)
- 2026-10-26

### Fixed

- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-prost`

<blockquote>

##
[0.14.7](tonic-prost-v0.14.6...tonic-prost-v0.14.7)
- 2026-10-26

### Fixed

- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- relax codec Default bounds
([#2681](#2681))
- License update ([#2749](#2749))
</blockquote>

## `tonic-health`

<blockquote>

##
[0.14.7](tonic-health-v0.14.6...tonic-health-v0.14.7)
- 2026-10-26

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-types`

<blockquote>

##
[0.14.7](tonic-types-v0.14.6...tonic-types-v0.14.7)
- 2026-10-26

### Fixed

- *(types)* Serialize `BadRequest::FieldViolation` `reason` and
`localized_message`
([#2461](#2461))
- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-reflection`

<blockquote>

##
[0.14.7](tonic-reflection-v0.14.6...tonic-reflection-v0.14.7)
- 2026-10-26

### Fixed

- *(reflection)* preserve custom options in served descriptors
([#2730](#2730))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- enable missing feature for test build
([#2820](#2820))
- License update ([#2749](#2749))
</blockquote>

## `tonic-prost-build`

<blockquote>

##
[0.14.7](tonic-prost-build-v0.14.6...tonic-prost-build-v0.14.7)
- 2026-10-26

### Fixed

- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-web`

<blockquote>

##
[0.14.7](tonic-web-v0.14.6...tonic-web-v0.14.7)
- 2026-10-26

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
LucioFranco pushed a commit that referenced this pull request Oct 27, 2026
## 🤖 New release

* `tonic`: 0.14.7 -> 0.14.8
* `tonic-build`: 0.14.7 -> 0.14.8
* `tonic-prost`: 0.14.7 -> 0.14.8
* `tonic-health`: 0.14.7 -> 0.14.8
* `tonic-types`: 0.14.7 -> 0.14.8
* `tonic-reflection`: 0.14.7 -> 0.14.8
* `tonic-prost-build`: 0.14.7 -> 0.14.8
* `tonic-web`: 0.14.7 -> 0.14.8 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

## `tonic`

<blockquote>

##
[0.14.7](tonic-v0.14.6...tonic-v0.14.7)
- 2026-10-26

### Fixed

- *(codec)* eliminate uninitialized memory in encode_item on unwind
([#2847](#2847))
- *(transport)* drop listener before draining connections
([#2824](#2824))
- fix/silence all clippy warnings
([#2807](#2807))
- *(status)* map h2 FRAME_SIZE_ERROR to Code::Internal
([#2641](#2641))
- *(codec)* respect server's enabled encodings when selecting response
compression ([#2655](#2655))

### Other

- *(deps)* require patched zstd
([#2962](#2962))
- fix changelog duplicate and update repository URLs
([#2943](#2943))
- *(deps)* require patched rustls-webpki and webpki-roots
([#2940](#2940))
- handle ipv6 endpoints when tls is enabled
([#2423](#2423))
- support immediate cancellation of streams without sending
End-of-Stream ([#2791](#2791))
- wrap connection_timeout in Fuse to prevent panic
([#2780](#2780))
- License update ([#2749](#2749))
</blockquote>

## `tonic-build`

<blockquote>

##
[0.14.7](tonic-build-v0.14.6...tonic-build-v0.14.7)
- 2026-10-26

### Fixed

- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-prost`

<blockquote>

##
[0.14.7](tonic-prost-v0.14.6...tonic-prost-v0.14.7)
- 2026-10-26

### Fixed

- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- relax codec Default bounds
([#2681](#2681))
- License update ([#2749](#2749))
</blockquote>

## `tonic-health`

<blockquote>

##
[0.14.7](tonic-health-v0.14.6...tonic-health-v0.14.7)
- 2026-10-26

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-types`

<blockquote>

##
[0.14.7](tonic-types-v0.14.6...tonic-types-v0.14.7)
- 2026-10-26

### Fixed

- *(types)* Serialize `BadRequest::FieldViolation` `reason` and
`localized_message`
([#2461](#2461))
- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-reflection`

<blockquote>

##
[0.14.7](tonic-reflection-v0.14.6...tonic-reflection-v0.14.7)
- 2026-10-26

### Fixed

- *(reflection)* preserve custom options in served descriptors
([#2730](#2730))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- enable missing feature for test build
([#2820](#2820))
- License update ([#2749](#2749))
</blockquote>

## `tonic-prost-build`

<blockquote>

##
[0.14.7](tonic-prost-build-v0.14.6...tonic-prost-build-v0.14.7)
- 2026-10-26

### Fixed

- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-web`

<blockquote>

##
[0.14.8](tonic-web-v0.14.7...tonic-web-v0.14.8)
- 2026-10-27

### Fixed

- *(tonic-web)* fix dropped trailers in combined streaming call.
([#2474](#2474))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
LucioFranco pushed a commit that referenced this pull request Oct 29, 2026
## 🤖 New release

* `tonic`: 0.14.8 -> 0.14.9 (✓ API compatible changes)
* `tonic-build`: 0.14.8 -> 0.14.9
* `tonic-prost`: 0.14.8 -> 0.14.9
* `tonic-health`: 0.14.8 -> 0.14.9
* `tonic-types`: 0.14.8 -> 0.14.9
* `tonic-reflection`: 0.14.8 -> 0.14.9
* `tonic-prost-build`: 0.14.8 -> 0.14.9
* `tonic-web`: 0.14.8 -> 0.14.9

<details><summary><i><b>Changelog</b></i></summary><p>

## `tonic`

<blockquote>

##
[0.14.9](tonic-v0.14.8...tonic-v0.14.9)
- 2026-10-29

### Added

- *(transport)* expose h2 reset stream settings on Endpoint
([#2972](#2972))

### Fixed

- *(server)* set a timer on HTTP/1 connections so hyper's header read
timeout applies ([#2980](#2980))
</blockquote>

## `tonic-build`

<blockquote>

##
[0.14.7](tonic-build-v0.14.6...tonic-build-v0.14.7)
- 2026-10-26

### Fixed

- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-prost`

<blockquote>

##
[0.14.7](tonic-prost-v0.14.6...tonic-prost-v0.14.7)
- 2026-10-26

### Fixed

- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- relax codec Default bounds
([#2681](#2681))
- License update ([#2749](#2749))
</blockquote>

## `tonic-health`

<blockquote>

##
[0.14.7](tonic-health-v0.14.6...tonic-health-v0.14.7)
- 2026-10-26

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-types`

<blockquote>

##
[0.14.7](tonic-types-v0.14.6...tonic-types-v0.14.7)
- 2026-10-26

### Fixed

- *(types)* Serialize `BadRequest::FieldViolation` `reason` and
`localized_message`
([#2461](#2461))
- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-reflection`

<blockquote>

##
[0.14.7](tonic-reflection-v0.14.6...tonic-reflection-v0.14.7)
- 2026-10-26

### Fixed

- *(reflection)* preserve custom options in served descriptors
([#2730](#2730))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- enable missing feature for test build
([#2820](#2820))
- License update ([#2749](#2749))
</blockquote>

## `tonic-prost-build`

<blockquote>

##
[0.14.7](tonic-prost-build-v0.14.6...tonic-prost-build-v0.14.7)
- 2026-10-26

### Fixed

- fix/silence all clippy warnings
([#2807](#2807))

### Other

- fix changelog duplicate and update repository URLs
([#2943](#2943))
- License update ([#2749](#2749))
</blockquote>

## `tonic-web`

<blockquote>

##
[0.14.8](tonic-web-v0.14.7...tonic-web-v0.14.8)
- 2026-10-27

### Fixed

- *(tonic-web)* fix dropped trailers in combined streaming call.
([#2474](#2474))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

BadRequest::FieldViolation reason and localized_message are not serialized

5 participants