Skip to content

Conversation

@joaopamaral
Copy link
Contributor

@joaopamaral joaopamaral commented Jun 21, 2023

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 format type to string %s to avoid the TypeError.

Test Example:

import logging

LOGGER = logging.getLogger('Test')
int_var = 1
str_var = '1'

LOGGER.warning('test with int var and number format %d', int_var)
LOGGER.warning('test with int var and string format %s', int_var)
LOGGER.warning('test with str var and string format %s', str_var)


# Exception
LOGGER.warning('test number format but string var %d', str_var)

Output

test with int var and number format 1
test with int var and string format 1
test with str var and string format 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 13, in <module>
    LOGGER.warning('test number format but string var %d', str_var)
Message: 'test number format but string var %d'
Arguments: ('1',)

@boring-cyborg
Copy link

boring-cyborg bot commented Jun 21, 2023

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 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 Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment 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 for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    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

@joaopamaral joaopamaral changed the title Fix LivyHook TypeError exception: Changing the log with sessing_id param to use f-string Fix LivyHook TypeError exception: Changing the sessing_id log format to %s Jun 26, 2023
@eladkal eladkal changed the title Fix LivyHook TypeError exception: Changing the sessing_id log format to %s Fix LivyHook TypeError exception on sessing_id log format Jun 27, 2023
@eladkal eladkal changed the title Fix LivyHook TypeError exception on sessing_id log format Fix LivyHook TypeError exception on session_id log format Jun 27, 2023
@eladkal eladkal merged commit 58784ad into apache:main Jun 27, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Jun 27, 2023

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

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.

3 participants