fossology / LicenseDb

GNU General Public License v2.0
12 stars 9 forks source link

refactor(external_ref): Remove unnecessary UpdateExternalRefsJSONPayload type #74

Closed deo002 closed 4 months ago

deo002 commented 5 months ago

Changes

Submitter Checklist

GMishx commented 5 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
}'

image

deo002 commented 5 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
}'

image

image

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.

GMishx commented 4 months ago

The external_ref still cannot not updated during testing.

GMishx commented 4 months ago

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.