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
Bug report: Updating a content type property with an empty value throws an exception #3718
Comments
Good catch! Would it solve the problem to force all unknown properties to be treated as a string or is the Description an exception here and we'd solve it by simply forcing just it to be treated as a string? |
I ran into it because I wanted to reset I tried I tried Could it be a problem with minimist? that it parses '' to true? |
By the way, this is in powershell. In zsh It seems the check if (options.description) {
requestBody.Description = options.description;
} does not add the property to the requestBody object. (I logged it to the console to see) So I guess this means it must be the minimist parser that's responsible. |
Correction, it has nothing to do with the API. The call is going through successfully. But the |
First thing we should try is to force these options to be treated as string by minimist and see if that solves it. |
Also, |
Hi @waldekmastykarz, TL;DRExplicitly treating the option as a string resolves the issue. What happens below the hoodSo I've added some logging statements, and this is what happens:
I see a subtle difference in the rawArgs coming in. And aside from that, minimist apparently tries to determine the type based on the value. I've tested this with |
Good to get this verified. The question stands: shall we treat all unknown options as strings to avoid side-effects of some values being treated as numbers or booleans? |
I think we should @waldekmastykarz ! But this behavior evidently also occurs on known options ( And by the way, this is actually also the reason for the discussion here In that situation, We need some bigger solution to encompass every scenario I fear. |
Where it makes sense, yes.
Let's start small and avoid trying to boil the ocean. |
If we would let all unknown options be parsed as strings, would we get into trouble with actual numbers or boolean fields that are saved to (for example) SharePoint |
Possibly. One way about it, it so leave unknown options as-is, and for the few options, define known equivalents which we handle properly. If we start adding specific unknown options to types, they won't make much of an unknown, wouldn't you say? 😄 |
@martinlingstuyl to bring this to a conclusion, shall we introduce a new |
@martinlingstuyl is this issue still relevant? Shall we proceed with what I proposed? Final ping before we close it as stale |
Hi @waldekmastykarz, it is still very relevant. I got a little sidetracked though. The issue does not only affect the Thinking about all this, I think we need a firmer solution that encompasses all these potential situations. As I see it we can go a few routes: Route 1: fix the immediate symptomWe could solve it by going through all known string options on cons:
Route 2: fix the culprit -> flag parsingThere's another route: we fix the culprit: Flag parsing. Minimist just assumes that any option without a value is a flag and parses it to We could therefore go down another route: help minimist by creating a As an alternate solution we could also add the flags to the pros
cons
I'm very interested to hear your take on this. |
By the way. Important side note here: I must first test if route 2 actually works :) I assume it does but I'm not sure. What I mean is that the ["spo", "contenttype", "set", "--someStringOption", "--anotherOption", "some value"]
My proposition is that we update the array to: ["spo", "contenttype", "set", "--someStringOption", "", "--anotherOption", "some value"] before passing it to minimist, based on |
According to me, |
Hi @milanholemans, the point is that So if you want to reset a field to an empty string, you cannot. |
Aw ok I see, should have read the entire thread, sorry! |
I'd like to clarify it a bit: this issue only affect string options that allow an empty value. Not all do, so let's keep that in mind when thinking of the impact of this issue on our code base. This also applies to number values that could be set to nothing: I don't know if that's actually possible or something that just might happen in theory without an actual example that we current have in the CLI. @martinlingstuyl have you tried wrapping the value in two set of quotes, like Also, before we set on a specific fix, let's double check that we won't be changing behavior that's native to all CLIs, where it's standard that |
I'm not on my PC right now, but have you also tried to use |
Not sure if I did, will try it asap! |
That actually works @milanholemans, @waldekmastykarz! using By the way, as said earlier: the problem with We could just leave the arg parsing as is, and add this oddity to the documentation, even if I still find it not very logical that it should work like this. What's your opinion on this? |
Nice to know that this works 😃 Maybe we can generalize it a bit and include the empty string argument as well. And what about passing a |
Great finding @milanholemans and it's weird that there's a difference between |
It's the PowerShell, not minimist. That's clear @waldekmastykarz . So we're agreed we're seeing this as a valid workaround and that we don't need to influence the args list for this ourselves? |
Correct @martinlingstuyl. |
In that case I'll close this issue and create a new one for updating the documentation! |
Description
If I run the following command:
The command throws a 400 exception.
The reason this happens is because the Description option is translated to a boolean when calling the API:
Steps to reproduce
Expected results
The property is emptied.
Actual results
The command crashes.
CLI for Microsoft 365 version
5.8 (next)
nodejs version
16.15.0
Operating system (environment)
Windows
Shell
PowerShell
Additional Info
This issue does not occur on bash.
The text was updated successfully, but these errors were encountered: