-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Raise a 404 exception when document source is not found (#33384) #34083
Raise a 404 exception when document source is not found (#33384) #34083
Conversation
Pinging @elastic/es-core-infra |
Hi, this PR is synced with |
Hi, this PR is synced with |
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 left a couple of inline comments. One for a slightly better result and a couple of small ones about hte test. Thanks @cbismuth!
assertThat(restResponse.content(), equalTo(new BytesArray("{\"foo\": \"bar\"}"))); | ||
} | ||
|
||
public void testRestGetSourceAction_withNullSource() { |
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 don't tend to like the _
in the method name. I'd just keep the camel 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.
No worries, let's keep the camel case, fixed in 40a59bc.
} | ||
|
||
public void testRestGetSourceAction() throws Exception { | ||
// GIVEN a REST Get Source action response with an existing result and a non-null source |
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 don't think the GIVEN, WHEN, THEN comments buy much here.
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.
Yes, you're right, fixed in c168b67.
final String type = response.getType(); | ||
final String id = response.getId(); | ||
|
||
throw new ResourceNotFoundException("Document or source not found [" + index + "]/[" + type + "]/[" + id + "]"); |
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.
If you check the exists
flag then is set the we could return "document not found" rather than "source not found".
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.
Good catch! Fixed in 3fac7c9, thank you 👍
@elasticmachine, test this please |
Hi @nik9000, thank you for you review, I've updated this PR and synced it with |
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 left a small thing. Could you fix it for my own paranoia?
* @throws ResourceNotFoundException if source or doc itself is missing | ||
*/ | ||
private void checkIfSourceEmpty(final GetResponse response) { | ||
if (response.isSourceEmpty()) { |
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'd prefer to check isExists
first because, at least in my head, isSourceEmpty
doesn't really make sense if the document doesn't exist. I know it works to do it this way, but it'd make me feel better to switch the order.
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.
You're totally right.
@elasticmachine, test this please |
@elasticmachine, test this please |
Thanks for iterating on it with me @cbismuth! I've kicked off a CI build for it. When it passes I'll merge it and backport it to 6.x. I wasn't 100% convinced that backporting to 6.x is appropriate because it is technically breaking, but empty string is already invalid JSON so I'm fine with declaring this a bug in the 6.x series and worth of this minor break. |
@elasticmachine, retest this please |
You're welcome @nik9000. I've just fixed Could you please trigger a CI build? Thanks you. |
@elasticmachine, test this please |
@elasticmachine retest this please |
Lets give that another shot. If that doesn't pass I'd merge master in again. |
Alright thanks @nik9000 👍 |
@cbismuth it looks like this needs master merged in because we're now depending on a different lucene snapshot. Would you like to do it? |
Sure, I’ll be back home on Monday, I’ll do it and let you know, thank you @nik9000. |
Hi @nik9000, PR is rebased with latest |
Hi, PR is up-to-date with latest |
PR is up-to-date with latest |
Hi @nik9000, I have not doubt you're hard working on many other things, so here is quick follow up:
So, this PR has just been updated with EDIT: build has started all by itself due to merge commit, I'll track this and let you know 😉 |
I've merged |
@elasticmachine, test this please. @cbismuth, sorry I dropped this one. I've had a rough past two weeks. I'm back now. |
No worries @nik9000, I'm glad you're doing well 👍 |
We have a green build 👍 |
OK @cbismuth! I've merged to master and backported to 6.x and am running integration tests for that locally. I'll let you know once they pass and I've pushed to 6.x. Thanks again! |
) This pull request makes the `RestGetSourceAction` return a `ResourceNotFoundException` with a proper JSON response when source or document itself is missing (see issue #33384). Here is below a sample JSON output: ``` { "error": { "root_cause": [ { "type": "resource_not_found_exception", "reason": "Source not found [index1]/[_doc]/[1]" } ], "type": "resource_not_found_exception", "reason": "Source not found [index1]/[_doc]/[1]" }, "status": 404 } ```
That is really nice, thanks a lot @nik9000 for your help and support 👍 |
That backport wasn't 100% clean, but I got it! 6.x had a lot of the same warning infrastructure, but build in slightly different ways. Anyway, it is in! Thanks for sticking with this @cbismuth! It was quite a trip. |
Woops, wrong issue! |
This pull request makes the
RestGetSourceAction
return aResourceNotFoundException
with a proper JSON response when source or document itself is missing (see issue #33384).Here is below a sample JSON output: