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

[conf] Add new coerce_list configuration type #4029

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sreenaths
Copy link
Collaborator

@sreenaths sreenaths commented Mar 7, 2025

What changes were proposed in this pull request?

  • Added a new configs datatype coerce_list
  • It could be used in Hue ini as follows
[section]
key="val 1", "val 2,3"

Note:

  • Safety: literal_eval() is generally safer than eval(), and current usage just accept list type. So it's safe.
  • coerce_csv breaks when we have coma (,) in the value. coerce_list provides a more robust way to configure.

How was this patch tested?

  • Manual test
  • UTs were added

@sreenaths sreenaths self-assigned this Mar 7, 2025
Copy link
Collaborator

@athithyaaselvam athithyaaselvam left a comment

Choose a reason for hiding this comment

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

LGTM!

@sreenaths sreenaths requested a review from amitsrivastava March 7, 2025 03:29
Copy link
Collaborator

@Harshg999 Harshg999 left a comment

Choose a reason for hiding this comment

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

Nice!

@Harshg999 Harshg999 changed the title Hue config - Support coerce_list configuration type [conf] Add new coerce_list configuration type Mar 7, 2025
def coerce_list(value) -> list:
if isinstance(value, str):
try:
result = ast.literal_eval(value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@sreenaths
There is still risk of memory exhaustion. What is the size of input expected? Limiting the size?
Take a look this: https://stackoverflow.com/questions/4710247/python-3-are-there-any-known-security-holes-in-ast-literal-evalnode-or-string

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had similar thought, but as this is an admin configuration felt its fine. Will see if there are any safer way to implement this.

Copy link

⚠️ No unit test files modified. Please ensure that changes are properly tested. ⚠️

Copy link

Backend Codecov

Backend Code Coverage Report •
FileStmtsMissCoverMissing
TOTAL533172613850% 
report-only-changed-files is enabled. No files were changed during this commit :)

Pytest Report

Tests Skipped Failures Errors Time
1088 107 💤 0 ❌ 0 🔥 4m 51s ⏱️

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.

4 participants