You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "joaopamaral (via GitHub)" <gi...@apache.org> on 2023/06/21 13:48:41 UTC
[GitHub] [airflow] joaopamaral opened a new pull request, #32051: Fix LivyHook TypeError exception: Changing the log with sessing_id param to use f-string
joaopamaral opened a new pull request, #32051:
URL: https://github.com/apache/airflow/pull/32051
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
Some methods in `LivyHook` expect the `session_id` as `int` or `str` but some log messages break when receiving a string but try to format it as number `%d`.
```
TypeError: %d format: a real number is required, not str
File "/opt/airflow/lib/python3.10/site-packages/airflow/providers/apache/livy/hooks/livy.py", line 286, in dump_batch_logs
self.log.info("Fetching the logs for batch session with id: %d", session_id)
Message: 'Fetching the logs for batch session with id: %d'
Arguments: ('11111',)
```
So this PR is changing the log to use `f-string` to avoid the TypeError.
Test Example:
```python
import logging
LOGGER = logging.getLogger('Test')
int_var = 1
str_var = '1'
LOGGER.warning('test with int var %d', int_var)
LOGGER.warning(f'test with fstring {int_var} {str_var}')
# Exception
LOGGER.warning('test expected numeric but string var %d', str_var)
```
Output
```
test with int var 1
test with fstring 1 1
--- Logging error ---
Traceback (most recent call last):
File "/Users/joaoamaral/.pyenv/versions/3.9.11/lib/python3.9/logging/__init__.py", line 1083, in emit
msg = self.format(record)
File "/Users/joaoamaral/.pyenv/versions/3.9.11/lib/python3.9/logging/__init__.py", line 927, in format
return fmt.format(record)
File "/Users/joaoamaral/.pyenv/versions/3.9.11/lib/python3.9/logging/__init__.py", line 663, in format
record.message = record.getMessage()
File "/Users/joaoamaral/.pyenv/versions/3.9.11/lib/python3.9/logging/__init__.py", line 367, in getMessage
msg = msg % self.args
TypeError: %d format: a number is required, not str
Call stack:
File "/Users/joaoamaral/Library/Application Support/JetBrains/PyCharm2022.1/scratches/scratch_13.py", line 11, in <module>
LOGGER.warning('test expected numeric but string var %d', str_var)
Message: 'test expected numeric but string var %d'
Arguments: ('1',)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] joaopamaral commented on a diff in pull request #32051: Fix LivyHook TypeError exception: Changing the sessing_id log format to %s
Posted by "joaopamaral (via GitHub)" <gi...@apache.org>.
joaopamaral commented on code in PR #32051:
URL: https://github.com/apache/airflow/pull/32051#discussion_r1242299345
##########
airflow/providers/apache/livy/hooks/livy.py:
##########
@@ -173,7 +173,7 @@ def post_batch(self, *args: Any, **kwargs: Any) -> int:
batch_id = self._parse_post_response(response.json())
if batch_id is None:
raise AirflowException("Unable to parse the batch session id")
- self.log.info("Batch submitted with session id: %d", batch_id)
+ self.log.info(f"Batch submitted with session id: {batch_id}")
Review Comment:
Indeed! Sounds better!
Changed to `%s`! Thanks
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] eladkal commented on a diff in pull request #32051: Fix LivyHook TypeError exception: Changing the log with sessing_id param to use f-string
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #32051:
URL: https://github.com/apache/airflow/pull/32051#discussion_r1241708716
##########
airflow/providers/apache/livy/hooks/livy.py:
##########
@@ -173,7 +173,7 @@ def post_batch(self, *args: Any, **kwargs: Any) -> int:
batch_id = self._parse_post_response(response.json())
if batch_id is None:
raise AirflowException("Unable to parse the batch session id")
- self.log.info("Batch submitted with session id: %d", batch_id)
+ self.log.info(f"Batch submitted with session id: {batch_id}")
Review Comment:
Why not just `%s` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] eladkal commented on a diff in pull request #32051: Fix LivyHook TypeError exception: Changing the log with sessing_id param to use f-string
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on code in PR #32051:
URL: https://github.com/apache/airflow/pull/32051#discussion_r1237623913
##########
airflow/providers/apache/livy/hooks/livy.py:
##########
@@ -173,7 +173,7 @@ def post_batch(self, *args: Any, **kwargs: Any) -> int:
batch_id = self._parse_post_response(response.json())
if batch_id is None:
raise AirflowException("Unable to parse the batch session id")
- self.log.info("Batch submitted with session id: %d", batch_id)
+ self.log.info(f"Batch submitted with session id: {batch_id}")
Review Comment:
See https://docs.python.org/3/howto/logging.html#optimization
f-string is not the prefered choice for logging module
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on pull request #32051: Fix `LivyHook` TypeError exception on `session_id` log format
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #32051:
URL: https://github.com/apache/airflow/pull/32051#issuecomment-1609760902
Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] eladkal merged pull request #32051: Fix `LivyHook` TypeError exception on `session_id` log format
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal merged PR #32051:
URL: https://github.com/apache/airflow/pull/32051
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on pull request #32051: Fix LivyHook TypeError exception: Changing the log with sessing_id param to use f-string
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #32051:
URL: https://github.com/apache/airflow/pull/32051#issuecomment-1600871299
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:
- Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
Apache Airflow is a community-driven project and together we are making it better 🚀.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] joaopamaral commented on a diff in pull request #32051: Fix LivyHook TypeError exception: Changing the log with sessing_id param to use f-string
Posted by "joaopamaral (via GitHub)" <gi...@apache.org>.
joaopamaral commented on code in PR #32051:
URL: https://github.com/apache/airflow/pull/32051#discussion_r1237630803
##########
airflow/providers/apache/livy/hooks/livy.py:
##########
@@ -173,7 +173,7 @@ def post_batch(self, *args: Any, **kwargs: Any) -> int:
batch_id = self._parse_post_response(response.json())
if batch_id is None:
raise AirflowException("Unable to parse the batch session id")
- self.log.info("Batch submitted with session id: %d", batch_id)
+ self.log.info(f"Batch submitted with session id: {batch_id}")
Review Comment:
Thanks for the comment @eladkal! So it will be better if we cast to int then?
```suggestion
self.log.info("Batch submitted with session id: %d", int(batch_id))
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org