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 "fallback cases" for relevant enums in :nessie-model #6634

Merged
merged 8 commits into from Apr 25, 2023

Conversation

snazy
Copy link
Member

@snazy snazy commented Apr 19, 2023

Adds custom deserializers for all enums in :nessie-model to make client & servers "safe" against new enum values. All relevant enums have a static ENUMTYPE parse(String) method, which falls back to a hard coded "safe default" value.

This apporach is meant to be prepared for emergency cases, when it is strictly necessary to add a new enum value. Or potentially also to let older clients continue to work "longer" against newer API/spec versions.

This approach is NOT meant as a workaround to add arbitrary enum values, it should still be avoided wherever and whenever possible to "just add enum value".

@snazy
Copy link
Member Author

snazy commented Apr 19, 2023

@dimas-b WDYT about this one? It is not a great one, but it might "safe our a.." at some point.

If you think this could be useful, I'll go ahead an finish it (tests and such)

Copy link
Member

@dimas-b dimas-b left a comment

Choose a reason for hiding this comment

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

I think this makes sense. Let's implement :)

@snazy snazy force-pushed the fallback-cases-for-enums branch 2 times, most recently from c0b5925 to c5ca7b3 Compare April 21, 2023 11:21
@snazy snazy marked this pull request as ready for review April 23, 2023 03:44
@snazy snazy requested a review from dimas-b April 23, 2023 03:45
@@ -399,8 +399,7 @@ public void testInvalidTag(String invalidTagName) {
.extract()
.as(NessieError.class)
.getMessage())
.contains(
"Could not resolve type id 'FOOBAR' as a subtype of `org.projectnessie.model.Reference`"));
.contains("assignReference.expectedHash: must not be null"));
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this still be something like "Reference type FOOBAR is not supported"? That is to say that we should probably report the same "unsupported" error on the server side regardless of the API method (assignReference.expectedHash: must not be null is specific to ref. assignment, but the real problem is that the ref. type is bogus).

Copy link
Member Author

Choose a reason for hiding this comment

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

It's ambiguous with this change to default to TAG

Copy link
Member

@dimas-b dimas-b Apr 25, 2023

Choose a reason for hiding this comment

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

Ah, right... I guess that default is meaningful only on the client side. If the server receives a reference with a type that it does not know about, that is probably a "bad request" regardless of how JSON serialization is done... WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's difficult. Opted to remove the change for ReferenceType.

}
return null;
} catch (IllegalArgumentException e) {
return TAG;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm trying to apply your ideas to #6646... Is the intent here to return a "random" enum constant when the text does not match any known enum constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a random one, but the "likely best match" / least-common-denominator

Adds custom deserializers for all enums in `:nessie-model` to make
client & servers "safe" against new enum values. All relevant enums have
a `static ENUMTYPE parse(String)` method, which falls back to a hard
coded "safe default" value.

This apporach is meant to be prepared for emergency cases, when it is
strictly necessary to add a new enum value. Or potentially also to let
older clients continue to work "longer" against newer API/spec versions.

This approach is _NOT_ meant as a workaround to add arbitrary enum
values, it should still be avoided wherever and whenever possible to
"just add enum value".
@snazy snazy changed the title Add "fallback cases" for all enums in :nessie-model Add "fallback cases" for relevan enums in :nessie-model Apr 25, 2023
@snazy snazy changed the title Add "fallback cases" for relevan enums in :nessie-model Add "fallback cases" for relevant enums in :nessie-model Apr 25, 2023
@snazy snazy requested a review from dimas-b April 25, 2023 21:38
@snazy snazy merged commit 4d4a356 into projectnessie:main Apr 25, 2023
24 checks passed
@snazy snazy deleted the fallback-cases-for-enums branch April 25, 2023 22:13
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

3 participants