Closed deo002 closed 4 months ago
I am unable to update the external_ref
of a license, other fields can be updates. Please check the sample request bellow:
curl -X 'PATCH' \
'http://localhost:8085/api/v1/licenses/MIT' \
-H 'accept: application/json' \
-H 'Authorization: mytoken' \
-H 'Content-Type: application/json' \
-d '{
"external_ref": {
"license_suffix": "GMishx"
},
"rf_risk": 4
}'
I am unable to update the
external_ref
of a license, other fields can be updates. Please check the sample request bellow:curl -X 'PATCH' \ 'http://localhost:8085/api/v1/licenses/MIT' \ -H 'accept: application/json' \ -H 'Authorization: mytoken' \ -H 'Content-Type: application/json' \ -d '{ "external_ref": { "license_suffix": "GMishx" }, "rf_risk": 4 }'
curl -X 'PATCH' \ 'http://localhost:5000/api/v1/licenses/MIT' \ -H 'accept: application/json' \ -H 'Authorization: token \ -H 'Content-Type: application/json' \ -d '{ "rf_risk": 4, "external_ref": { "license_suffix": "GMishX" } }'
Wierdly enough, its working for me. I'll look into it.
The external_ref
still cannot not updated during testing.
From debugging discussion, the default value for external_ref
in my Database is null
. This causes gorm.Expr("jsonb_strip_nulls(external_ref || ?)", updates.ExternalRef)
to return null
as null || '{myjson}'::json
in PostgreSQL will return null.
I recommend to compare the oldLicense.ExternalRef
and updates.ExternalRef
in Go to create a final ExternalRef
which can be passed to PostgreSQL without using the ||
operator. Doing so, we can be sure null
on either side (existing or new value) should not make the entire JSON object as null
.
Changes
Submitter Checklist