Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make #[diesel(embed)] fields be somewhat-checked by #[check_for_backend] #4484

Merged

Conversation

Ten0
Copy link
Member

@Ten0 Ten0 commented Feb 13, 2025

Currently when a struct has #[derive(Selectable)], #[check_for_backend(...)], and embeds another Selectable struct that doesn't have #[check_for_backend] but whose FromSqlRow and Selectable impls don't match with regards to CompatibleType, the #[check_for_backend] does not point us to which of the embed fields is the culprit, because they are ignored.

It seems that this can be avoided by generating the checks even for embed fields.

The compatibility check was disabled on #[embed] fields in d6d9260 when the experimented-with approach was "always generating the check on Selectable" with the justification that it was consequently checked by the underlying field's own Selectable checks, before it was decided to instead have the #[check_for_backend(...)] attribute, so it seems that this justification was indeed legitimate at the time it was introduced, and doesn't hold anymore now.

…ckend]`

Currently when a struct has `#[derive(Selectable)]`, `#[check_for_backend(...)]`, and `embed`s another `Selectable` struct that doesn't have `#[check_for_backend]` but whose `FromSqlRow` and `Selectable` impls don't match with regards to `CompatibleType`, the `#[check_for_backend]` does not point us to which of the embed fields is the culprit, because they are ignored.

It seems that this can be avoided by generating the checks even for `embed` fields.

The check for this was disabled in d6d9260 when the experimented-with approach was "always generating the check on Selectable" with the justification that it was consequently checked by the underlying field's own Selectable checks, before it was decided to instead have the `#[check_for_backend(...)]` attribute, so it seems that this justification was indeed legitimate at the time it was introduced, and doesn't hold anymore now.
@Ten0 Ten0 marked this pull request as draft February 13, 2025 15:57
@Ten0 Ten0 marked this pull request as ready for review February 13, 2025 17:24
@Ten0 Ten0 force-pushed the check_embed_fields_with_check_for_backend branch from e9e8890 to a824e0d Compare February 13, 2025 17:26
@Ten0 Ten0 requested a review from a team February 13, 2025 18:53
@weiznich weiznich added the maybe backport Maybe backport this pr to the latest diesel release label Feb 14, 2025
@weiznich weiznich added this pull request to the merge queue Feb 14, 2025
Merged via the queue into diesel-rs:master with commit 73d2518 Feb 14, 2025
35 checks passed
weiznich added a commit to weiznich/diesel that referenced this pull request Feb 14, 2025
This commit prepares a 2.2.8 release that includes the following
changes:

* diesel-rs#4472
* diesel-rs#4484
* diesel-rs#4486
* diesel-rs#4480
weiznich added a commit to weiznich/diesel that referenced this pull request Feb 14, 2025
This commit prepares a 2.2.8 release that includes the following
changes:

* diesel-rs#4472
* diesel-rs#4484
* diesel-rs#4486
* diesel-rs#4480
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maybe backport Maybe backport this pr to the latest diesel release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants