← Back to Pull requests

Implement TupleSize for SelectBy so nested selectable tuples load #5240

Open
LucaCappelletti94 opened this pull request with 412 lines diff across 6 files
View on GitHub
LucaCappelletti94 LucaCappelletti94 commented on Sep 23, 2026 07:32 UTC
Author

A tuple of as_select() expressions nested inside another tuple failed to compile unless it was the last element, which also broke wrapping such a select in a custom query like the pagination example from the issue.

This was a rare example of vertical brown touch, as I ended up finding a completely unrelated and real bug in Ubuntu while working on this 🤦🏻

Closes #4292

Diff: 412 lines (+373 / -39) across 6 files Reviewer: weiznich Review duration: 23912m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.46) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 412 lines diff across 6 files
0.46
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.93 · 4 substantive comment(s)
0.93
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.360
Real PR Conversation Timeline
5 items
weiznich weiznich commented on code on Sep 25, 2026 12:16 UTC
Code Review
diesel_tests/tests/select_by.rs:1
@@ -232,6 +232,74 @@ fn mixed_selectable_and_plain_select() {
     assert_eq!(expected_data, actual_data);
 }
 
+#[diesel_test_helper::test]
+fn nested_tuple_of_selectables_followed_by_plain_select() {
+    use crate::schema::users::dsl::*;
+
+    let connection = &mut connection_with_sean_and_tess_in_users_table();
+
+    let expected_data = vec![
+        (
+            (
+                User {
+                    id: 1,
+                    name: "Sean".to_string(),
+                    hair_color: None,
+                },
+                UserName::new("Sean"),
+            ),
+            1,
+        ),
+        (
+            (
+                User {
+                    id: 2,
+                    name: "Tess".to_string(),
+                    hair_color: None,
+                },
+                UserName::new("Tess"),
+            ),
+            2,
+        ),
+    ];
+    let actual_data: Vec<((User, UserName), i32)> = users
+        .select(((User::as_select(), UserName::as_select()), id))

By looking at this I noticed that it might be that this impl doesn't exist was an explicit decision back the.

The reason might be that ::as_select() generally seeks to enforce that only that type can be loaded from the database, not anything that's compatible in shape. I think that construct would loosen that guarantee. The existing, checked way here is to use <(User, UserName)>::as_select() instead

codecov[bot] codecov[bot] commented on Sep 25, 2026 19:58 UTC
Bot

Codecov Report


:x: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 81.50%. Comparing base (cb82e6a) to head (48f39a8).
:warning: Report is 9 commits behind head on main.

| Files with missing lines | Patch % | Lines |
|---|---|---|
| diesel/src/type\_impls/tuples.rs | 0.00% | 0 Missing and 1 partial :warning: |

<details><summary>Additional details and impacted files</summary>

@@           Coverage Diff           @@
##             main    #5240   +/-   ##
=======================================
  Coverage   81.49%   81.50%           
=======================================
  Files         337      337           
  Lines       36626    36626           
  Branches    36626    36626           
=======================================
+ Hits        29850    29853    +3     
+ Misses       5049     5045    -4     
- Partials     1727     1728    +1     

| Flag | Coverage Δ | |
|---|---|---|
| mariadb | 76.45% <0.00%> (+0.01%) | :arrow_up: |
| mysql | 76.53% <0.00%> (+0.01%) | :arrow_up: |
| postgres | 80.05% <0.00%> (+0.01%) | :arrow_up: |
| sqlite | 76.17% <0.00%> (+0.01%) | :arrow_up: |

Flags with carried forward coverage won't be shown. Click here to find out more.
</details>

:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
<details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    LucaCappelletti94 LucaCappelletti94 commented on Sep 27, 2026 09:33 UTC
    Author

    I imagine that your "loosen that guarantee" means having incorrect queries survive compile time. I did found one case regarding the Untyped case, and I do handle it now. I could not find anything else.

    Experimentally, before crashing to bed, I started a Opus 5.5 armed with several Qwen 3.8 27b in a container over night to search for related bugs adversarially (I prompted the agent to find an hypothetical bug I claimed is there, so it can get desperate searching for it), as I cannot think of a better fuzzer for it at this time. It could not find one.

    If you have any ideas or gut feelings about what could break here, do let me know and I can try to have a look at it or try another run as described above, although I am not sure whether it not finding anything means it is just useless at it.

    LucaCappelletti94 LucaCappelletti94 commented on Oct 01, 2026 12:17 UTC
    Author

    And the Ubuntu bug I mentioned & patched originally is now getting released next week yay https://bugs.launchpad.net/ubuntu/+source/sqlite3/+bug/2087772

    Reviewers
    Assignees
    LucaCappelletti94 LucaCappelletti94
    Labels
    risk: low confidence: 90.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.4% (MEDIUM) · Higher = larger blast radius
    46.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.7% · Lower = rushed or shallow review
    90.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.3% · Safe to merge
    4.3%