go-gerrit icon indicating copy to clipboard operation
go-gerrit copied to clipboard

Projects.SetConfig endpoint fails with 400 Bad Request due to ConfigInput.MaxObjectSizeLimit zero value not being omitted

Open wuhuang26 opened this issue 3 years ago • 5 comments

I create TestProjectsService_SetConfig func to test SetConfig requests api fail error info: failed: 400 Bad Request Invalid application/json in request

I find ConfigInput field is MaxObjectSizeLimitInfo, change type string can be success...

wuhuang26 avatar May 27 '22 02:05 wuhuang26

Thanks for reporting.

Since the field is optional, MaxObjectSizeLimitInfo is definitely not right as it'll always be included despite the omitempty tag, while *MaxObjectSizeLimitInfo would allow the zero value to be properly omitted.

The documentation for the ConfigInput entity says:

The max object size limit of this project as a MaxObjectSizeLimitInfo entity. If set to 0, the max object size limit is removed. If not set, this setting is not updated.

The first and last paragraph suggests that *MaxObjectSizeLimitInfo would be right. However, the "if set to 0" part suggests maybe it can be a string or integer value too? To allow that, I think we'd need to use interface{} and let the user provide the desired type.

It's also possible the documentation is incorrect, though, since the example request shows a string being used:

"max_object_size_limit": "10m",

dmitshur avatar May 27 '22 12:05 dmitshur

From the first look, interfae{} looks like the way to go here. Proper inline documentation would be very useful to have to describe the possible values.

andygrunwald avatar May 27 '22 18:05 andygrunwald

@andygrunwald It should be possible to infer the type from Gerrit's code. If ProjectInput.java is the right place to look, then using string as implemented in PR #112 looks right (and Gerrit REST API documentation needs updating).

dmitshur avatar May 28 '22 01:05 dmitshur

You are right. The interface is more suitable and flexible

At 2022-05-27 20:32:38, "Dmitri Shuralyov" @.***> wrote:

Thanks for reporting.

Since the field is optional, MaxObjectSizeLimitInfo is definitely not right as it'll always be included despite the omitempty tag, while *MaxObjectSizeLimitInfo would allow the zero value to be properly omitted.

The documentation for the ConfigInput entity says:

The max object size limit of this project as a MaxObjectSizeLimitInfo entity. If set to 0, the max object size limit is removed. If not set, this setting is not updated.

The first and last paragraph suggests that *MaxObjectSizeLimitInfo would be right. However, the "if set to 0" part suggests maybe it can be a string or integer value too? To allow that, I think we'd need to use interface{} and let the user provide the desired type.

It's also possible the documentation is incorrect, though, since the example request shows a string being used:

"max_object_size_limit": "10m",

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

wuhuang26 avatar May 30 '22 01:05 wuhuang26

I found that the configinfo setting parameter does not take effect, such as State、SubmitType、Actions

wuhuang26 avatar May 30 '22 02:05 wuhuang26