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
Allow importing partial backup (fixes #4672) #4705
Conversation
@@ -133,7 +133,8 @@ pub async fn import_settings( | |||
local_user_view.local_user.id, | |||
&local_user_form, | |||
) | |||
.await?; | |||
.await | |||
.ok(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes all error types to be ignored. Things like connection problems should not be ignored. Try making it only ignore QueryBuilderError.
@@ -133,7 +133,8 @@ pub async fn import_settings( | |||
local_user_view.local_user.id, | |||
&local_user_form, | |||
) | |||
.await?; | |||
.await |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than doing this, check this out from the diesel update docs:
It should be noted that receiving 0 rows from get_result is considered an error condition by default. If you want to get back 0 or 1 row (e.g. have a return type of QueryResult<Option>), then you will need to call .get_result(...).optional().
So I'd recommend doing the same thing I did for inserts, but for all updates: adding .optional()
so that we can catch the runtime errors. IMO this should be done for all updates, so we can handle that case.
If you want me to handle this, lmk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would not hadle the case of all fields in the update form being set to None, which throws QueryBuilderError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to open up an issue in diesel for this, bc it needs a similar solution to optional()
then, or optional should also handle that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the meantime, you can do a match on that specific err.kind()
https://stackoverflow.com/a/43884600/1655478
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, it should be Err(Error::QueryBuilderError(_)) =>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good.
b287627
to
811e0f2
Compare
LocalUser::update
was throwing an error if there was nothing changed. Not sure whyPerson::update
is working as both queries seem identical.