Skip to content

Conversation

Yashb404
Copy link

Changes
This change addresses an issue where sending a PATCH request with an empty JSON body ({}) to the /licenses/{shortname} endpoint would cause all fields of the corresponding license to be set to NULL in the database. This was happening because the LicenseUpdateDTO struct was being populated with nil values, which GORM then interpreted as an instruction to nullify the database columns.

Handle Empty Request Body: The UpdateLicense function in pkg/api/licenses.go now checks if the request body is empty. If it is, the function returns the existing data without making any changes, preventing accidental data loss.

Selective Field Updates: The function now uses a map to ensure that only the fields explicitly provided in the PATCH request are updated. This aligns with the expected behavior of a PATCH request and prevents unintended side effects.

Fixes #148

Submitter Checklist
[x] Includes tests (if there is a feature changed/added)

[ ] Includes docs ( if changes are user facing)

[x] I have tested my changes locally.

References
N/A

@ChayanDass
Copy link
Contributor

ChayanDass commented Sep 18, 2025

hi @ Yashb404, you should first verify the issue!
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Object with all null values returned in PATCH requests

2 participants