-
Notifications
You must be signed in to change notification settings - Fork 115
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
Inconsistent behaviour between Config.getValue()
and Config.getOptionalValue()
#83
Comments
So I was about to send a PR but now I noticed that there is already a test that assumes this to be incorrect. |
I'd say that the expected value should be an empty array. And The spec would deserve some clarification in this area. |
I meant to say that it should return an empty And yes, spec seems to be lenient here. |
@kenfinnigan @jmesnil what are your thoughts on this? |
Is this around determining the difference between a non set value and a set to nothing value? It does make sense for I'm not familiar with the spec intricacies, so not sure if this would need spec clarification |
It's more so about MP Concurrency is currently trying to use similar setup where it is valid to provide a "nothing value". |
Related spec pr is eclipse/microprofile-config#407 |
as @manovotn commented, I've opened a PR to clarify mp-config specification. For optional values, an empty config property MUST return an |
@dmlloyd @kenfinnigan I don't think #102 PR solves this issue. Sorry I couldn't review earlier, was on PTO. |
Hmm I didn't notice that behavior. Easy enough to fix it though, one second :) |
Here's a wrinkle though: I can't find anything in the spec that clarifies empty string behavior. So it looks like there is going to be some legwork here. I'm on it though |
@dmlloyd yeah, I think we mentioned it in previous comments here on this issue. |
In the meantime, reopening this issue. |
Fixes smallrye#83 (for real)
Bad news. The TCK tests that the result of an empty string is an empty string rather than a missing value. This creates a big inconsistency in the way things work. |
That's actually how I would expect it to work though. |
Fixes smallrye#83 (for real)
It must though. If an empty string translates to an empty array, then it must also translate to a non-present value. If an empty string is not a non-present value, it becomes impossible to override a present value with a non-present one, and in addition, it must translate to a single-element array containing an empty string otherwise translating the empty string versus |
In other words, if |
@dmlloyd I've no issues with you raising it at spec level |
@dmlloyd @kenfinnigan Uf, so with this change, how are you supposed to figure out if there is a configuration key, but it has an empty value? BTW the aforementioned setting is OFC tested in MP CP TCK hence will cause failures in SR impl on SR config version bump. EDIT: apparently using |
This change treats an empty value as a missing property by design. It's not clear to the user that writes the configuration what According to https://github.com/eclipse/microprofile-context-propagation/blob/7c7ac8558b2a8890aacc323e5df009a9a3f0b4f5/api/src/main/java/org/eclipse/microprofile/context/ManagedExecutor.java#L227, With that change, you should be able to fix https://github.com/smallrye/smallrye-context-propagation/blob/2d434f7739457c133c39304faa65c0c57bdc52b9/core/src/main/java/io/smallrye/context/impl/DefaultValues.java#L44-L47 by using |
@jmesnil Using |
@manovotn my question is, what does a missing value signify if an empty string means "don't propagate anything"? BTW I've found it useful to represent default values as a "bottom priority" config source, if that helps. This is an idea that might be worth formalizing in the spec. Just adding a clarification. If you're using a missing value to determine whether to use a default, you're definitely in for some pain no matter what. By putting the defaults in as a config source, an empty value can be always safely treated the same as a missing value, and can have whatever semantic meaning is associated with such a value. |
@kenfinnigan I already went over it with Jeff on Zulip and created a MP CP issue (eclipse/microprofile-context-propagation#160) to introduce some constant basically meaning "nothing". So long as the spec change goes through, we can keep this closed and I'll try to mend this on MP CP side. But to explain it, @dmlloyd , the thing is that every implementation has its default values for propagated/cleared/unchanged (for |
As I said, using not-present to indicate a default doesn't really work (for anyone). If the default value (which could be impl-defined, for sure) was established in a bottom priority config source, then you don't have to do anything at all: not-present can still mean "no context", and if it is present, then either the user specified a value or it fell through to the default value. Does this make sense? |
Hm, so I might be late to the party but if I have a config property |
No, you don't need to do anything like that. You'd use |
@mkouba you would use an optional value:
|
So in other words I can't use the |
@mkouba or you can do:
and specifies
|
Well, that's not very obvious. Also a regular user does not care about config sources at all. |
"low ordinal config source" can a microprofile-config.properties in your jar (that's not seen by the user) |
Why not? The CDI integration can do the optional part for you. But you do have to know what an empty value means. |
As I said, the downside to using a config source with a low priority is that all your defaults need to be known up front. With the CDI integration at least, I think the default value can vary by use site, so already this doesn't work. So a |
I'm really sorry for my ignorance but I don't understand. |
You would get the default value if the value was not specified in the properties file. You would get an empty string/missing value if the user specifies |
I think Martin's problem is very similar to what I tried to describe. And in this case using |
If so then I see no other way then to inject |
It already does this though. You pass the default you want into the config accessor. If the value is not specified, you get the default back. If the value is specified as empty, you get an empty value. |
But then you get to a point where for one configuration, say,
That doesn't sounds consistent. |
No, under the present proposal, in your third case you'd get |
Uff, we are running in circles here. Lemme reformulate. Assuming a config file with key |
You have the following options, as it is currently specified: // there's no default value
String[] array = config.getOptionalValue("my.key", String[].class).orElse(EMPTY_ARRAY);
// there's a default value
String[] array = config.access("my.key", String[].class).withStringDefault("foo,bar").getOptionalValue().orElse(EMPTY_ARRAY); I think it still might be worth introducing a shortcut for the second one, like this: String[] array = config.getOptionalValue("my.key", String[].class, "foo,bar"); But in this case I don't know if the default should normally be |
I stumbled upon the different behaviour of
Config.getValue()
andConfig.getOptionalValue()
method.When you define a configuration and give it an empty value, e.g. something like
org.foo.bar=
(expected value here isString[]
, thengetValue()
will (IMO correctly) return empty string, whereasgetOptionalValue()
gives me empty optional which I cannot retrieve.Now, I don't really see spec mentioning this in detail, but those two methods should behave equally.
The text was updated successfully, but these errors were encountered: