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

Allow importing partial backup (fixes #4672) #4705

Merged
merged 3 commits into from May 15, 2024
Merged

Conversation

Nutomic
Copy link
Member

@Nutomic Nutomic commented May 6, 2024

LocalUser::update was throwing an error if there was nothing changed. Not sure why Person::update is working as both queries seem identical.

@@ -133,7 +133,8 @@ pub async fn import_settings(
local_user_view.local_user.id,
&local_user_form,
)
.await?;
.await
.ok();

Copy link
Collaborator

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
Copy link
Member

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.

Copy link
Collaborator

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

Copy link
Member

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.

Copy link
Member

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

Copy link
Collaborator

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(_)) =>

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed now.

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

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

Seems good.

@dessalines dessalines merged commit 723cb54 into main May 15, 2024
2 checks passed
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.

None yet

4 participants