8000 fix: `LoggingProxy.write()` return type by ruaridhw · Pull Request #6791 · celery/celery · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: LoggingProxy.write() return type #6791

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

Merged
merged 2 commits into from
May 31, 2021

Conversation

ruaridhw
Copy link
Contributor
@ruaridhw ruaridhw commented May 28, 2021

Note: Before submitting this pull request, please review our contributing
guidelines
.

Description

Updates the return type of LoggingProxy.write() such that it conforms to IO.write().

Additionally, removes the mutation of written data such as stripping whitespace. That said, this is quite a subjective change and was clearly added for a reason in the first place... It just feels odd to me that if LoggingProxy's only job is to forward streams that it would also mutate them along the way.

Fixes #6790

Ruaridh Williamson added 2 commits May 28, 2021 16:17
- The API of `IO.write()` is to return `int` corresponding to the length of the message
- If we're substituting this class for `sys.stdout` it needs to follow the same interface
- The caller may intend to print whitespace to stdout
- If they don't want this whitespace then ideally the calling method should control this rather than `LoggingProxy` mutating the message
@ruaridhw ruaridhw force-pushed the fix/loggingproxywrite branch from 076ff25 to 51f5b01 Compare May 28, 2021 15:17
@codecov
Copy link
codecov bot commented May 28, 2021

Codecov Report

Merging #6791 (51f5b01) into master (025bad6) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #6791   +/-   ##
=======================================
  Coverage   70.63%   70.64%           
=======================================
  Files         138      138           
  Lines       16594    16598    +4     
  Branches     2089     2090    +1     
=======================================
+ Hits        11722    11726    +4     
  Misses       4677     4677           
  Partials      195      195           
Flag Coverage Δ
unittests 70.64% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
celery/utils/log.py 54.16% <100.00%> (+1.30%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c93371d...51f5b01. Read the comment docs.

@auvipy
Copy link
Member
auvipy commented May 30, 2021

Additionally, removes the mutation of written data such as stripping whitespace. That said, this is quite a subjective change and was clearly added for a reason in the first place... It just feels odd to me that if LoggingProxy's only job is to forward streams that it would also mutate them along the way.

I want to know more thought on this

@auvipy auvipy merged commit b0ebc3b into celery:master May 31, 2021
@ruaridhw ruaridhw deleted the fix/loggingproxywrite branch June 7, 2021 14:07
@auvipy auvipy added this to the 5.1.x milestone Jun 15, 2021
jeyrce pushed a commit to jeyrce/celery that referenced this pull request Aug 25, 2021
* fix: `LoggingProxy.write()` return type

- The API of `IO.write()` is to return `int` corresponding to the length of the message
- If we're substituting this class for `sys.stdout` it needs to follow the same interface

* Don't mutate data to log

- The caller may intend to print whitespace to stdout
- If they don't want this whitespace then ideally the calling method should control this rather than `LoggingProxy` mutating the message
@@ -223,7 +223,6 @@ def write(self, data):
if getattr(self._thread, 'recurse_protection', False):
# Logger is logging back to this file, so stop recursing.
return 0
data = data.strip()
if data and not self.closed:
Copy link
Contributor
@mabouels mabouels Oct 19, 2021

Choose a reason for hiding this comment

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

@ruaridhw: The strip() used to also remove newlines added by the print() function. With this fix, output of print() redirected to the logger will result in two newlines, instead of just one.

Copy link
Member

Choose a reason for hiding this comment

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

can you provide a qick fix plz?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank You!

Copy link
Contributor Author
@ruaridhw ruaridhw Oct 26, 2021

Choose a reason for hiding this comment

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

Good point, @mabouels. The reason I removed this originally, is that there might be intentional whitespace lines logged for the purposes of spacing/alignment. @auvipy's fix seems like it will work for both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Celery breaks libs using sys.stdout.write()
3 participants
0