Skip to content

Conversation

@KJhellico
Copy link
Collaborator

Proposed change

Introduce HolidayBase::__getstate__ and HolidayBase::__setstate__ methods for proper serialization of holidays objects.
Resolve #1236.

Type of change

  • New country/market holidays support (thank you!)
  • Supported country/market holidays update (calendar discrepancy fix, localization)
  • Existing code/documentation/test/process quality improvement (best practice, cleanup, refactoring, optimization)
  • Dependency update (version deprecation/pin/upgrade)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (a code change causing existing functionality to break)
  • New feature (new holidays functionality in general)

Checklist

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Summary by CodeRabbit

  • Refactor

    • Enhanced the handling of holiday translations and state management for more consistent and reliable display of localized holiday data.
  • Tests

    • Expanded test coverage to ensure that holiday information remains accurate and consistent across different language settings during data persistence operations.

Walkthrough

The changes involve restructuring the translation initialization in the HolidayBase class by introducing a private method _init_translation, which is called after the object is fully constructed. Additionally, the class now includes __getstate__ and __setstate__ methods for managing serialization and deserialization. A new test method, test_pickle_localized_entity, has been added to verify that localized holiday entities retain their integrity during the pickling process across different language settings.

Changes

File Change Summary
holidays/holiday_base.py Introduced _init_translation for translation setup; added __getstate__ and __setstate__ for serialization handling.
tests/test_holiday_base.py Added test_pickle_localized_entity to test serialization and deserialization of localized holiday entities in multiple languages.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ef839a and eaa6a31.

📒 Files selected for processing (1)
  • holidays/holiday_base.py (4 hunks)
⏰ Context from checks skipped due to timeout of 300000ms (1)
  • GitHub Check: Test build on windows-latest
🔇 Additional comments (4)
holidays/holiday_base.py (4)

370-371: Translation initialization refactored to a separate method.

The code now calls a dedicated method _init_translation() after object construction, which creates a cleaner separation of concerns and improves code organization.


570-574: Properly handles state preparation for serialization.

The method correctly prepares the object's state by removing the translation function that can't be serialized. The implementation is defensive by using pop with None as a fallback value, which prevents errors if the "tr" key doesn't exist in the state dictionary.


683-686: Ensures proper state restoration after deserialization.

After updating the object's state, the method correctly reinitializes the translation function by calling _init_translation(), ensuring the object works properly after being unpickled.


739-766: Well-implemented translation initialization method.

The _init_translation method properly encapsulates the translation setup logic. It:

  1. Sets up entity-native content translations
  2. Adds fallback translations for parent entities when applicable
  3. Assigns the appropriate translation function to the tr attribute

This implementation aligns with the PR objective of enhancing holiday object serialization, as the translation function can now be properly reinitialized after unpickling.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

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.

@github-actions github-actions bot added the test label Mar 6, 2025
@codecov
Copy link

codecov bot commented Mar 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e2f0790) to head (eaa6a31).
Report is 5 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##               dev     #2333    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          203       204     +1     
  Lines        12402     12569   +167     
  Branches      1777      1797    +20     
==========================================
+ Hits         12402     12569   +167     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2f0790 and 9658a5f.

📒 Files selected for processing (2)
  • holidays/holiday_base.py (4 hunks)
  • tests/test_holiday_base.py (1 hunks)
⏰ Context from checks skipped due to timeout of 300000ms (1)
  • GitHub Check: Test build on windows-latest
🔇 Additional comments (3)
tests/test_holiday_base.py (1)

870-879: Good implementation of pickle serialization test for localized entities.

The test properly verifies that holiday entities with different language settings can be correctly serialized and deserialized while maintaining their state.

holidays/holiday_base.py (2)

737-765: Well-structured method for translation initialization.

Good refactoring to extract the translation initialization logic from __init__ into a dedicated method. This improves code organization and supports the serialization process.


681-684: Good implementation of state restoration.

The method correctly restores the object's state and reinitializes the translation function, completing the serialization cycle.

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

@KJhellico paying off my technical debts 😄? I appreciate it. A lot!

Thank you!

Co-authored-by: Arkadii Yakovets <[email protected]>
Signed-off-by: ~Jhellico <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 8, 2025

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@arkid15r arkid15r enabled auto-merge March 8, 2025 16:38
Copy link
Collaborator

@PPsyrius PPsyrius left a comment

Choose a reason for hiding this comment

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

LGTM 🛠️

@arkid15r arkid15r added this pull request to the merge queue Mar 9, 2025
Merged via the queue into vacanza:dev with commit df64840 Mar 9, 2025
33 checks passed
@KJhellico KJhellico deleted the fix-pickle branch March 9, 2025 18:21
@KJhellico KJhellico mentioned this pull request Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't pickle the result of country_holidays

3 participants