fix: System_output returns a byte string (bytes) not a string (str)#6242
Conversation
|
Warning Rate limit exceeded@xianglongfei-8888 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 6 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThe pull request modifies the Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes
Areas to spot-check:
Pre-merge checks✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
avocado/utils/process.py (1)
82-82: Fix is correct; consider usinggetoutput()for cleaner code.The decode is necessary since
system_outputreturns bytes. However, this file already providesgetoutput()(lines 1162-1220) which returns a string directly and handles encoding automatically, eliminating the need for manual decoding.Apply this diff to use
getoutput()for cleaner, more maintainable code:- if system_output("id -u", ignore_status=True, sudo=True).decode('utf-8').strip() == "0": + if getoutput("id -u", sudo=True).strip() == "0":Note:
getoutput()hasignore_status=Trueas its default, so it can be omitted.
|
@clebergnu Could you help review the code? Thanks! |
clebergnu
left a comment
There was a problem hiding this comment.
Hi @xianglongfei-8888 ,
Good catch! The result of system_output is indeed bytes and not a string. But, the better solution is to avoid forcing encoding types because the system under which the id -u command runs may be configured with a different locale. It's true that the result should be numeric only, which would always decode properly under "utf-8", but, it's a good practice to not assume that.
So, my suggestion is to use avocado.utils.process.getoutput() which uses the default encoding (from avocado.utils.atring.ENCODING).
95baa3b to
b1804d5
Compare
@clebergnu Yes, you're absolutely right. Thank you for your advice |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6242 +/- ##
==========================================
+ Coverage 73.48% 73.52% +0.03%
==========================================
Files 206 206
Lines 22494 22497 +3
==========================================
+ Hits 16530 16540 +10
+ Misses 5964 5957 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: xianglongfei <xianglongfei@uniontech.com>
b1804d5 to
6d01c2f
Compare
sudo id -u : 'b'0''

System_output returns a byte string (bytes), not a string (str).
Will cause "can_sudo" to consistently return False
We need to use. decode ('utf-8 ') to convert the byte string into a string.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.