Make empty changeset updates using `.optional()` , either ignore or bypass errors `QueryBuilderError` s.
dessalines opened this issue · 0 comments
Setup
Versions
- Rust: - rustc 1.80.0-nightly (9c9b56879 2024-05-05)
- Diesel: - 2.1.6
- Database: - Postgres 16
- Operating System - Arch
Feature Flags
- diesel: NA
Problem Description
Oftentimes, when doing DB updates, we need to build changeset objects, where we don't know beforehand if its an empty changeset, IE if all the updated fields are None
.
When that's the case, diesel throws a runtime QueryBuilderError, which needs to be explicitly caught.
We'd like to either ignore, or bypass that error completely, rather than having to catch runtime QueryBuilderError s for every single update in our application.
The best solution IMO, would be to add this functionality to the existing .optional()
, which already does a similar function: turning empty get_result
from an error to an option.
Adding this would also turn an empty update / changeset into an Option. IE, if .optional()
is done, convert a QueryBuilderError into None
, rather than throwing a runtime error.
Context: LemmyNet/lemmy#4705
Checklist
- I have already looked over the issue tracker and the discussion forum for similar possible closed issues.
- This issue can be reproduced on Rust's stable channel. (Your issue will be
closed if this is not the case) - This issue can be reproduced without requiring a third party crate