Skip to content

added validation for retention period for send files by email#4723

Open
rparke wants to merge 1 commit intomainfrom
rp-add-validation-for-retention-period-for-send-files
Open

added validation for retention period for send files by email#4723
rparke wants to merge 1 commit intomainfrom
rp-add-validation-for-retention-period-for-send-files

Conversation

@rparke
Copy link
Contributor

@rparke rparke commented Feb 3, 2026

document-download-api already validates at the point of sending, but we should try and catch any errors at the point of file creation too.

document-download-api already validates at the point of sending, but we should try and catch any errors at the point of file creation too.
Copy link
Contributor

@CrystalPea CrystalPea left a comment

Choose a reason for hiding this comment

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

Nice one, I left a comment 🙌🏼

<= instance
<= DOCUMENT_DOWNLOAD_RETENTION_UPPER_LIMIT_IN_WEEKS
)
raise ValidationError(f"Unsuported value for for retention period: {instance}. Supported values are 1 to 78")
Copy link
Contributor

@CrystalPea CrystalPea Feb 4, 2026

Choose a reason for hiding this comment

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

Let's keep it consistent with the message in validate_schema_retention_period():

Suggested change
raise ValidationError(f"Unsuported value for for retention period: {instance}. Supported values are 1 to 78")
raise ValidationError(f"Unsupported value for for retention period: {instance}. Supported periods are from 1 to 78 weeks.")

Also looks like that and this function have a lot in common - maybe we could refactor them to be one function?

Copy link
Contributor Author

@rparke rparke Feb 4, 2026

Choose a reason for hiding this comment

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

The issue is that these are validating in subtly different ways. Document download API expects a string of the form "<number of weeks> weeks", notifications-api just expects an int that represents a number of weeks. So we want the error message to clearly tell us what it expects (an int, not a string).

We could probably refactor those into the same method, but I wanted it to be explicitly exactly what we're validating in the schema "are we validating requests to v2 or are we validating requests from admin to be handled by the send files by email feature?". I'm happy to be persuaded that code maintainability trump that distinction though.

Copy link
Contributor

@CrystalPea CrystalPea Feb 4, 2026

Choose a reason for hiding this comment

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

That makes sense! Let's keep separate validation messages then. Maybe this one could be amended to:

Suggested change
raise ValidationError(f"Unsuported value for for retention period: {instance}. Supported values are 1 to 78")
raise ValidationError(f"Unsupported value for for retention period: {instance}. Supported values are integers from 1 to 78")

I would still refactor this:

(
    DOCUMENT_DOWNLOAD_RETENTION_LOWER_LIMIT_IN_WEEKS
    <= instance
    <= DOCUMENT_DOWNLOAD_RETENTION_UPPER_LIMIT_IN_WEEKS
)

into a helper method, like _is_valid_retention_period(number) - what do you think?

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.

2 participants