You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While using bigip.ModifyInternalDataGroupRecords() we encountered a possible issue.
The steps to reproduce it are as follows:
There is only 1 record in a data group left;
Executing ModifyInternalDataGroupRecords() with an empty slice results with success;
Going to BIG-IP instance to check, the record is still there. For the BIG-IP system nothing is changed.
Reading the code and looking more specifically over the DataGroupRecord to dataGroupDTO structs, the Records field tag in dataGroupDTO is json:"records,omitempty". This leads to the behaviour described above. When passing empty/nil slice, the omitempty tag will remove the object from the json send to the BIG-IP system.
We are thinking of 2 possible solutions.
Removing the omitempty tag
This will quickly solve the issue. As seen in the code, the ModifyInternalDataGroupRecords() function is the only one modifying the DataGroupRecord resource. However, if another modifying function is introduced in the future, this removed tag, can lead to overwritten data group records in BIG-IP.
Distinguishing between nil slice records and empty slice records
This leads to modifying the marshal() function and adding case for nil/empty slices. The downside of this approach is that distinguishing between empty and nil slice is a bad practise by a lot of clean code guides.
Please feel free to share your opinion and guidance how we can handle this behaviour. Whatever is decided, we can contribute it.
The text was updated successfully, but these errors were encountered:
Hi @scottdware, do you have any comments here? We will contribute the fix, we would just like to have some thoughts from you what would you consider a good fix. Thanks!
@svetlinas@stoyanr I'm good with either option you want to submit. The first choice seems to be the simplest way to accomplish this. Go ahead and submit a PR and I'll merge it when it comes in.
While using
bigip.ModifyInternalDataGroupRecords()
we encountered a possible issue.The steps to reproduce it are as follows:
Reading the code and looking more specifically over the
DataGroupRecord
todataGroupDTO
structs, the Records field tag indataGroupDTO
isjson:"records,omitempty"
. This leads to the behaviour described above. When passing empty/nil slice, theomitempty
tag will remove the object from the json send to the BIG-IP system.We are thinking of 2 possible solutions.
omitempty
tagThis will quickly solve the issue. As seen in the code, the
ModifyInternalDataGroupRecords()
function is the only one modifying the DataGroupRecord resource. However, if another modifying function is introduced in the future, this removed tag, can lead to overwritten data group records in BIG-IP.This leads to modifying the
marshal()
function and adding case for nil/empty slices. The downside of this approach is that distinguishing between empty and nil slice is a bad practise by a lot of clean code guides.Please feel free to share your opinion and guidance how we can handle this behaviour. Whatever is decided, we can contribute it.
The text was updated successfully, but these errors were encountered: