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

Add .optional() to database fetches that shouldn't throw an error for zero-result single-row-fetches. #4601

Closed
5 tasks done
dessalines opened this issue Apr 5, 2024 · 2 comments · Fixed by #4617
Closed
5 tasks done

Comments

@dessalines
Copy link
Member

dessalines commented Apr 5, 2024

Requirements

  • Is this a feature request? For questions or discussions use https://lemmy.ml/c/lemmy_support
  • Did you check to see if this issue already exists?
  • Is this only a feature request? Do not put multiple feature requests in one issue.
  • Is this a backend issue? Use the lemmy-ui repo for UI / frontend issues.
  • Do you agree to follow the rules in our Code of Conduct?

Is your proposal related to a problem?

When doing a single-row DB fetch, diesel will throw an error if there is no row returned.

This affects .get_result, .first, and maybe other aliases I'm unaware of.

In the code, we have various wrappers / methods to prevent errors from zero result single-fetches, but we should just be using .optional() instead.

As far as I'm aware, list fetches do not throw an error if there are zero results returned.

Describe the solution you'd like.

Use .optional() for single-fetches that shouldn't return an error.

Grep for the expressions above, add .optional(), and trace down and remove any error-catching hacks.

Describe alternatives you've considered.

NA

Additional context

#4580 (comment)

@Nutomic
Copy link
Member

Nutomic commented Apr 8, 2024

Can you link these wrappers in our code which should be removed?

dessalines added a commit that referenced this issue Apr 11, 2024
- Diesel ordinarily throws an error when no results are returned for a
  single fetch, which is a bit confusing. This PR ensures that the
  missing value cases are all caught, and wrapped with new LemmyErrors,
  rather than diesel errors.
- Fixes #4601
@dessalines
Copy link
Member Author

dessalines commented Apr 11, 2024

I made a huge PR to make all these single-row options, and found and fixed a lot of uncaught cases in the process.

Nutomic pushed a commit that referenced this issue Apr 16, 2024
- Diesel ordinarily throws an error when no results are returned for a
  single fetch, which is a bit confusing. This PR ensures that the
  missing value cases are all caught, and wrapped with new LemmyErrors,
  rather than diesel errors.
- Fixes #4601
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants