Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ready for review] Add explicit max length control for foreach value. #1733

Merged
merged 2 commits into from
Feb 20, 2024

Conversation

darinyu
Copy link
Collaborator

@darinyu darinyu commented Feb 15, 2024

Add a length control for final result as string. This will prevent us from generating a list of foreach value with crazy long value.

@darinyu darinyu changed the title Add explicit max length control for foreach value. [Ready for review] Add explicit max length control for foreach value. Feb 15, 2024
@@ -529,7 +530,7 @@ def _is_primitive_type(item):
)

value = item if _is_primitive_type(item) else reprlib.Repr().repr(item)
return basestring(value)
return basestring(value)[:MAXIMUM_VALUE_CHARACTERS]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Repr already has a default limit of 30 already - I imagine this change only affects primitives right now. I would recommend setting the value of maxstring to MAX_CHARS so that if the value of MAX_CHARS is modified in the future - you can expect a consistent response if repr is in action.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Repr doc is ambiguous, the maxstring=30 for Repr means that the string inside the represented result is <=30 (it doesn't truncate the entire representation to maxstring. for example,

reprlib.Repr().repr({"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": "bbbbbbbbbbbbbbbbbbbbbbb"})
"{'aaaaaaaaaaaa...aaaaaaaaaaaaa': 'bbbbbbbbbbbbbbbbbbbbbbb'}"

romain-intel
romain-intel previously approved these changes Feb 16, 2024
Copy link
Contributor

@romain-intel romain-intel left a comment

Choose a reason for hiding this comment

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

LGTM

@savingoyal savingoyal merged commit 314d6f4 into master Feb 20, 2024
31 of 34 checks passed
@savingoyal savingoyal deleted the add_foreach_value_maximum_len branch February 20, 2024 23:30
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