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

feat: Allow usage of print() within safe_exec() #23084

Merged
merged 9 commits into from
Nov 20, 2023

Conversation

akhilnarang
Copy link
Member

@akhilnarang akhilnarang commented Nov 3, 2023

This resolves #22582

print() can now be used within safe_exec() calls - server scripts, system console, etc.

For system console, it shows normally in output
image

For server scripts, a new field has been added Debug Log

image

For doc events and API, the printed values are part of debug log.

image

[no-docs]

@akhilnarang akhilnarang requested review from a team and surajshetty3416 and removed request for a team November 3, 2023 07:52
@github-actions github-actions bot added the add-test-cases Add test case to validate fix or enhancement label Nov 3, 2023
@akhilnarang akhilnarang changed the title feat: Allow usage of print() within safe_eval() feat: Allow usage of print() within safe_exec() Nov 3, 2023
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Merging #23084 (7b11e28) into develop (94b2e50) will increase coverage by 0.03%.
Report is 37 commits behind head on develop.
The diff coverage is 45.65%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #23084      +/-   ##
===========================================
+ Coverage    62.18%   62.22%   +0.03%     
===========================================
  Files          770      770              
  Lines        73970    73997      +27     
  Branches      6346     6345       -1     
===========================================
+ Hits         45997    46043      +46     
- Misses       24361    24364       +3     
+ Partials      3612     3590      -22     
Flag Coverage Δ
server 70.71% <45.65%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ankush ankush requested review from sagarvora and removed request for ankush November 3, 2023 09:11
frappe/__init__.py Outdated Show resolved Hide resolved
@akhilnarang akhilnarang force-pushed the restrictedpython-print branch 4 times, most recently from 918186c to 84a6747 Compare November 3, 2023 12:08
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
…tead of `log()`

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
@akhilnarang
Copy link
Member Author

akhilnarang commented Nov 6, 2023

Current state works fine, just has this warning

frappe-bench/env/lib/python3.11/site-packages/RestrictedPython/compile.py:204: SyntaxWarning: Line None: Prints, but never reads 'printed' variable.
warnings.warn(

Comes from https://github.com/zopefoundation/RestrictedPython/blob/master/src/RestrictedPython/transformer.py#L478-L509
https://github.com/zopefoundation/RestrictedPython/blob/master/src/RestrictedPython/transformer.py#L630

RestrictedPython warns us if we call `print()` don't use their `printed` variable

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This can be moved to level 2 when required
@ankush ankush added the squash label Nov 20, 2023
@ankush ankush merged commit eb45da3 into frappe:develop Nov 20, 2023
19 of 25 checks passed
@ankush ankush added do not backport and removed add-test-cases Add test case to validate fix or enhancement labels Nov 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2023
@ankush ankush added backport version-15-hotfix Backport the PR to v15 and removed do not backport labels Apr 19, 2024
@akhilnarang akhilnarang deleted the restrictedpython-print branch April 19, 2024 20:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support print statements in safe_exec
2 participants