Skip to content

fix(trait/value)raise validation error if trait_value is too long - #307

Merged
dabeeeenster merged 2 commits into
mainfrom
fix/github-294
Sep 13, 2021
Merged

fix(trait/value)raise validation error if trait_value is too long#307
dabeeeenster merged 2 commits into
mainfrom
fix/github-294

Conversation

@gagantrivedi

Copy link
Copy Markdown
Member

closes #294


if data_type == STRING and len(data) > TRAIT_VALUE_MAX_LENGTH:
raise serializers.ValidationError(
"Value string is too long. Must be less than 2000 character"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Value string is too long. Must be less than 2000 character"
f"Value string is too long. Must be less than {TRAIT_VALUE_MAX_LENGTH} character"

from features.value_types import BOOLEAN, FLOAT, INTEGER, STRING

ACCEPTED_TRAIT_VALUE_TYPES = [INTEGER, STRING, BOOLEAN, FLOAT]
TRAIT_VALUE_MAX_LENGTH = 2000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should be explicit here and specify it as something like:

TRAIT_STRING_VALUE_MAX_LENGTH = 2000


# Then
assert res.status_code == status.HTTP_400_BAD_REQUEST
assert "string is too long" in res.json()["trait_value"][0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not assert the exact error message - it's not much more code.

@matthewelwell matthewelwell removed their assignment Sep 13, 2021
@matthewelwell matthewelwell removed their assignment Sep 13, 2021
@dabeeeenster
dabeeeenster merged commit 5637989 into main Sep 13, 2021
@dabeeeenster
dabeeeenster deleted the fix/github-294 branch September 13, 2021 20:24
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.

Gracefully handle traits that are too large (over 2000 bytes)

3 participants