Skip to content

Conversation

ruitcatarino
Copy link

This PR refactors how log levels are handled in the taskiq CLI to avoid using behavior that Python's logging documentation explicitly considers incorrect.

Background

According to the Python logging documentation, using getLevelName() to convert string level names to integers (like "INFO" to 20) is explicitly "considered a mistake".

In Python versions earlier than 3.4, this function could also be passed a text level, and would return the corresponding numeric value of the level. This undocumented behaviour was considered a mistake, and was removed in Python 3.4, but reinstated in 3.4.2 due to retain backward compatibility.

Changes

This PR refactors the LogLevel enum to inherit from IntEnum instead of str, storing the actual logging module constants (logging.INFO, logging.WARNING, etc.) as enum values. The enum members are now integers by nature, which can be passed directly to logging functions without any conversion.

Modified files:

  • taskiq/cli/common_args.py: Changed LogLevel to IntEnum with logging constant values
  • taskiq/cli/scheduler/args.py: Added string to enum conversion in argument parsing
  • taskiq/cli/scheduler/run.py: Updated to use log_level directly as integer
  • taskiq/cli/worker/args.py: Added string to enum conversion in argument parsing
  • taskiq/cli/worker/run.py: Updated to use log_level directly as integer

Compatibility

The CLI interface remains unchanged. Users can still pass log levels as strings:

taskiq worker my_broker --log-level INFO
taskiq scheduler my_scheduler --log-level DEBUG

The string is converted to the appropriate LogLevel enum member during argument parsing, and since the enum values are integers, they work directly with the logging module.

Benefits

This approach uses the proper API as intended by Python's logging module. The solution is type safe, and maintains full backward compatibility with existing CLI usage.

@ruitcatarino ruitcatarino changed the title fix: replace deprecated getLevelName with IntEnum for log levels fix: replace getLevelName with IntEnum for log levels Oct 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant