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

Automatically fall back to create when edit fails for endpoints that support it #3378

Open
2 tasks done
trevor-vaughan opened this issue Aug 15, 2023 · 2 comments
Open
2 tasks done
Labels
type:feature Changes add a new feature

Comments

@trevor-vaughan
Copy link

Description

When using ProjectPushRules.edit() I discovered that, when nothing is originally set, GitLab will deny the edit with a 404 message.

There are two solutions:

  1. Call ProjectPushRules.show() to see if there is something there in the first place and choose which to call based on that (2 API calls)
  2. Call ProjectPushRules.edit(), catch the error, and fall back on ProjectPushRules.create() with the exact same options.

Proposal

Given that edit() and create() have the exact same inputs, I would like to propose automatically falling back when possible so that the expected result occurs without the user needing to code around the edge cases.

Checklist

  • I have checked that this is not a duplicate issue.
  • I have read the documentation.
@jdalrymple
Copy link
Owner

I've thought about this for other endpoints as well, but decided to not support it since I'm trying to match the API as much as possible. Though it would be helpful, It feels like functionality that should be supported in the API itself, or at least discussed in the API itself to have an upsert functionality as opposed to the wrapper.

Definitely on the fence on this one. It could be handy

@jdalrymple jdalrymple added the type:feature Changes add a new feature label Aug 17, 2023
@trevor-vaughan
Copy link
Author

I totally agree that it really should be in GitLab itself but I think that the chances of it getting in within 2+ years is slim :-(.

I decided to ask for the feature when I found myself writing the code everywhere anyway. Maybe make it a toggle that defaults to true just in case someone wants more fine grained control over the fallback?

Personally, I can't think of a time when you wouldn't want to fall back but edge cases are like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature Changes add a new feature
Projects
None yet
Development

No branches or pull requests

2 participants