Skip to content

Conversation

@BarathaAberathne
Copy link
Contributor

What

  • Added validations to prevent using spaces for dataset-id and edition id when POSt, PUT
  • Added component tests & unit tests

How to review

Who can review

anyone

@BarathaAberathne BarathaAberathne requested a review from a team as a code owner December 22, 2025 07:44
Copy link
Contributor

@franmoore05 franmoore05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Providing an edition field as part of the body on a POST /versions and /versions/{number} which contained spaces allowed me to complete the request successfully. The validation should be consistent and fail if an edition is provided in the body with the value "test 123" so this needs to be resolved.


if err := utils.ValidateIDNoSpaces(datasetID); err != nil {
log.Error(ctx, "addDatasetVersionCondensed endpoint: dataset ID contains spaces", err, logData)
return nil, models.NewErrorResponse(http.StatusBadRequest, nil, models.NewError(err, errs.ErrSpacesNotAllowedInID.Error(), errs.ErrSpacesNotAllowedInID.Error()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code and description values required by models.NewError appear to be duplicated, these should be different.


if err := utils.ValidateIDNoSpaces(datasetID); err != nil {
log.Error(ctx, "createVersion endpoint: dataset ID contains spaces", err, logData)
return nil, models.NewErrorResponse(http.StatusBadRequest, nil, models.NewError(err, errs.ErrSpacesNotAllowedInID.Error(), errs.ErrSpacesNotAllowedInID.Error()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As previously mentioned, the code and description values required by models.NewError appear to be duplicated, these should be different.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are still returning duplicate values. Please see previous comment.


if err := utils.ValidateIDNoSpaces(edition); err != nil {
log.Error(ctx, "createVersion endpoint: edition ID contains spaces", err, logData)
return nil, models.NewErrorResponse(http.StatusBadRequest, nil, models.NewError(err, errs.ErrSpacesNotAllowedInID.Error(), errs.ErrSpacesNotAllowedInID.Error()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, duplicate values have been provided for code and description.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are still returning duplicate values. Please see previous comment.

Copy link
Contributor

@franmoore05 franmoore05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes be addressed (clicked the wrong radio button)

return nil, models.NewErrorResponse(http.StatusBadRequest, nil, models.NewError(err, models.JSONUnmarshalError, "failed to unmarshal version"))
}

if newVersion.Type == models.Static.String() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this check been added here? If a record is being processed in the static_versions.go file then it would only be of a static type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you’re right. Since this code path is only reached for records handled in static_versions.go, the type will always be static. The additional check is unnecessary, so I’ll remove it.


// Populate distributions (static only)
// Populate distributions & validate spaces in IDs(static only)
if version.Type == models.Static.String() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a check for static type on line 371, could this section be moved in there to avoid the duplicate if statements?

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.

3 participants