Skip to content

fix(package): Add StatusIntEnum class to match the behavior of IntEnum in Python 3.11.#1133

Merged
haiqi96 merged 11 commits into
y-scope:mainfrom
haiqi96:slight_refactor_2
Aug 5, 2025
Merged

fix(package): Add StatusIntEnum class to match the behavior of IntEnum in Python 3.11.#1133
haiqi96 merged 11 commits into
y-scope:mainfrom
haiqi96:slight_refactor_2

Conversation

@haiqi96

@haiqi96 haiqi96 commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Description

This PR adds StatusIntEnum which derived on IntEnum so that __str__'s behavior is aligned with python 3.11, as documented in here

In our code, we currently rely on the database connector to implicilty convert the scheduler enums when writting them to the database.
Note that when using mysql, the library (likely mysql-connector-python ) converts the enum using str(). With a lower python version, the enum will be converted to string and cause an error.

As a sollution, this PR introduce StatusIntEnum which overloads the str method, and let all status related enum to derive on StatusIntEnum.

To reproduce, change the database type to "mysql" and compress any input logs. the compression scheduler will fail with error log:

Traceback (most recent call last):
  File "/opt/clp/lib/python3/site-packages/mysql/connector/connection_cext.py", line 697, in cmd_query
    self._cmysql.query(
_mysql_connector.MySQLInterfaceError: Unknown column 'CompressionJobStatus.RUNNING' in 'field list'

Note the same issue is not observed when using mariadb, which could be internally handled by mariadb's python library.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Configured database.type = mysql
Compressed mongodb log from local file storage, ensured the compression scheduler doesn't crash

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced status display options for compression job and task statuses, allowing for improved string representations in the user interface.

@coderabbitai

coderabbitai Bot commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A new base class StatusIntEnum inheriting from IntEnum was introduced to unify and centralize the string representation methods for several enums. Existing enums in the scheduler constants were updated to inherit from this base class, removing redundant string methods and maintaining existing static methods unchanged.

Changes

Cohort / File(s) Change Summary
Enum Base Class and Refactoring
components/job-orchestration/job_orchestration/scheduler/constants.py
Added StatusIntEnum base class with __str__ and to_str methods; updated multiple enums to inherit from it and removed their explicit string methods.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between adcbf75 and fed9010.

📒 Files selected for processing (1)
  • components/job-orchestration/job_orchestration/scheduler/constants.py (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: haiqi96
PR: y-scope/clp#0
File: :0-0
Timestamp: 2025-07-29T14:04:13.769Z
Learning: User haiqi96 requested creating a GitHub issue to document a bug fix from PR #1136, which addressed MySQL compatibility issues with invalid SQL CAST operations in the WebUI component.
📚 Learning: user haiqi96 requested creating a github issue to document a bug fix from pr #1136, which addressed ...
Learnt from: haiqi96
PR: y-scope/clp#0
File: :0-0
Timestamp: 2025-07-29T14:04:13.769Z
Learning: User haiqi96 requested creating a GitHub issue to document a bug fix from PR #1136, which addressed MySQL compatibility issues with invalid SQL CAST operations in the WebUI component.

Applied to files:

  • components/job-orchestration/job_orchestration/scheduler/constants.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint-check (ubuntu-24.04)
  • GitHub Check: lint-check (macos-15)
🔇 Additional comments (2)
components/job-orchestration/job_orchestration/scheduler/constants.py (2)

14-24: Centralising the conversion logic looks solid

The new StatusIntEnum removes the previous repetition and cleanly back-ports Python 3.11’s IntEnum.__str__ behaviour. Both __str__ and to_str are minimal and correct.
No issues spotted here – nice consolidation.


23-24: Nice catch removing the redundant cast

Returning self.name directly is cleaner than the prior str(self.name) call.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@haiqi96 haiqi96 changed the title fix( fix(package): Add string utilities for job orchestration enum. Jul 28, 2025
@haiqi96 haiqi96 changed the title fix(package): Add string utilities for job orchestration enum. fix(package): Add string utilities for job orchestration enums. Jul 28, 2025
@haiqi96 haiqi96 marked this pull request as ready for review July 28, 2025 14:34
@haiqi96 haiqi96 requested a review from a team as a code owner July 28, 2025 14:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
components/job-orchestration/job_orchestration/scheduler/constants.py (2)

31-36: Same duplication observation as above – refer to the earlier comment for the proposed mix-in approach.


44-49: Same duplication observation as above – refer to the earlier comment for the proposed mix-in approach.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a84ce14 and 470713a.

📒 Files selected for processing (1)
  • components/job-orchestration/job_orchestration/scheduler/constants.py (1 hunks)

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On ec2's arm machine, without those methods, python convert enums to int instead of string and has caused failures when updating the database.

Mind giving a code example of how the enum is converted?

@haiqi96

haiqi96 commented Jul 29, 2025

Copy link
Copy Markdown
Contributor Author

On ec2's arm machine, without those methods, python convert enums to int instead of string and has caused failures when updating the database.

Mind giving a code example of how the enum is converted?

one example can be found here
https://github.com/y-scope/clp/blob/main/components/job-orchestration/job_orchestration/scheduler/compress/compression_scheduler.py#L249.

Inside update_compression_job_metadata(), the compression_job_status enum will be converted, I guess the str method will be implicitly called.

@haiqi96 haiqi96 requested a review from junhaoliao July 31, 2025 01:49
@haiqi96 haiqi96 changed the title fix(package): Add string utilities for job orchestration enums. fix(package): Add __str()__ method for job orchestration enums for mysql support. Jul 31, 2025
@haiqi96 haiqi96 changed the title fix(package): Add __str()__ method for job orchestration enums for mysql support. fix(package): Add __str()__ method for job orchestration enums for MySQL compatibility. Jul 31, 2025
@haiqi96 haiqi96 changed the title fix(package): Add __str()__ method for job orchestration enums for MySQL compatibility. fix(package): Add __str()__ and to_str() method for job orchestration enums for MySQL compatibility. Jul 31, 2025

@junhaoliao junhaoliao Jul 31, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

instead of overriding individual classes' __str__ method, can we add a mixin like

class IntEnumStrMixin:
    """
    Delegates __str__ to int.__str__, matching the behavior of IntEnum
    in Python 3.11+.
    TODO: Remove this when our minimum supported Python version is 3.11+.
    """

    def __str__(self):
        return int.__str__(self.__getattribute__("value"))

class CompressionJobStatus(IntEnumStrMixin, IntEnum):
    PENDING = 0
    RUNNING = auto()
    SUCCEEDED = auto()
    FAILED = auto()

alternatively, we can also extend the IntEnum class into a custom class and let the existing enum classes extend from it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated my code. let me know if you agree with the current approach. If you don't see any issues, I will then update the PR description.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 470713a and adcbf75.

📒 Files selected for processing (1)
  • components/job-orchestration/job_orchestration/scheduler/constants.py (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: haiqi96
PR: y-scope/clp#0
File: :0-0
Timestamp: 2025-07-29T14:04:13.769Z
Learning: User haiqi96 requested creating a GitHub issue to document a bug fix from PR #1136, which addressed MySQL compatibility issues with invalid SQL CAST operations in the WebUI component.
📚 Learning: user haiqi96 requested creating a github issue to document a bug fix from pr #1136, which addressed ...
Learnt from: haiqi96
PR: y-scope/clp#0
File: :0-0
Timestamp: 2025-07-29T14:04:13.769Z
Learning: User haiqi96 requested creating a GitHub issue to document a bug fix from PR #1136, which addressed MySQL compatibility issues with invalid SQL CAST operations in the WebUI component.

Applied to files:

  • components/job-orchestration/job_orchestration/scheduler/constants.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint-check (macos-15)
  • GitHub Check: build (macos-15)
  • GitHub Check: lint-check (ubuntu-24.04)
🔇 Additional comments (1)
components/job-orchestration/job_orchestration/scheduler/constants.py (1)

14-21: Centralizing __str__/to_str logic via StatusIntEnum cleans up the module nicely

Moving the duplicated methods into a single base class addresses the earlier DRY feedback and keeps future enum additions painless. 👍

Comment thread components/job-orchestration/job_orchestration/scheduler/constants.py Outdated

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

for the title, how about

fix(package): Add `__str()__` and `to_str()` methods to job orchestration enums for MySQL connector compatibility.

@haiqi96

haiqi96 commented Aug 3, 2025

Copy link
Copy Markdown
Contributor Author

for the title, how about

fix(package): Add `__str()__` and `to_str()` methods to job orchestration enums for MySQL connector compatibility.

I will think about the title since now I am introducing a new class. Will let you know when I finish updating the PR.

@haiqi96 haiqi96 changed the title fix(package): Add __str()__ and to_str() method for job orchestration enums for MySQL compatibility. fix(package): Add StatusIntEnum class to match behavior the behavior of IntEnum in python 3.11. Aug 4, 2025
@haiqi96 haiqi96 changed the title fix(package): Add StatusIntEnum class to match behavior the behavior of IntEnum in python 3.11. fix(package): Add StatusIntEnum class to match the behavior of IntEnum in python 3.11. Aug 4, 2025
@haiqi96 haiqi96 requested a review from junhaoliao August 4, 2025 20:48

@junhaoliao junhaoliao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the title, let's capitalize the "P" in "Python"

@haiqi96 haiqi96 changed the title fix(package): Add StatusIntEnum class to match the behavior of IntEnum in python 3.11. fix(package): Add StatusIntEnum class to match the behavior of IntEnum in Python 3.11. Aug 5, 2025
@haiqi96 haiqi96 merged commit ac6f359 into y-scope:main Aug 5, 2025
7 checks passed
junhaoliao pushed a commit to junhaoliao/clp that referenced this pull request May 17, 2026
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.

2 participants