Skip to content

Conversation

aaronsteers
Copy link
Contributor

@aaronsteers aaronsteers commented Jan 29, 2025

Summary by CodeRabbit

  • New Features

    • Added ab_datetime_try_parse function for flexible datetime parsing.
    • Enhanced datetime parsing to support more input formats, including various separators.
    • Added to_datetime method for converting AirbyteDateTime to standard datetime.
    • Improved datetime formatting with optional custom format support.
  • Bug Fixes

    • Improved error handling for invalid datetime inputs.
    • Refined validation logic for datetime parsing, ensuring better error messaging.

@aaronsteers aaronsteers marked this pull request as ready for review January 29, 2025 23:04
@github-actions github-actions bot added bug Something isn't working security labels Jan 29, 2025
Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

📝 Walkthrough

Walkthrough

The pull request introduces enhancements to datetime handling utilities in the Airbyte CDK. The modifications focus on improving datetime parsing and formatting flexibility, with new functions like ab_datetime_try_parse that gracefully handle datetime string parsing. The changes expand support for various datetime formats, add more robust error handling, and provide additional conversion methods for the AirbyteDateTime class.

Changes

File Changes
airbyte_cdk/utils/datetime_helpers.py - Added ab_datetime_try_parse() method to safely parse datetime strings
- Updated ab_datetime_parse() to handle more delimiter formats
- Added to_datetime() method to AirbyteDateTime class
- Modified ab_datetime_format() to support optional custom formatting
unit_tests/utils/test_datetime_helpers.py - Added test cases for broader datetime format support
- Removed strict format validation tests
- Added tests for ab_datetime_try_parse() behavior

Sequence Diagram

sequenceDiagram
    participant Input as Datetime String
    participant Parser as ab_datetime_parse()
    participant TryParser as ab_datetime_try_parse()
    participant Formatter as ab_datetime_format()

    Input->>TryParser: Attempt parsing
    alt Parsing Successful
        TryParser-->>Input: Return AirbyteDateTime
    else Parsing Failed
        TryParser-->>Input: Return None
    end

    Input->>Parser: Parse datetime
    Parser-->>Input: Return AirbyteDateTime

    Input->>Formatter: Format datetime
    Formatter-->>Input: Return formatted string
Loading

Suggested reviewers

  • bnchrch
  • alafanechere
  • natikgadzhi
  • brianjlai

How do you feel about the proposed reviewers? Do you think there are others who might be relevant?

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4f9e926 and 5d060dc.

📒 Files selected for processing (1)
  • unit_tests/utils/test_datetime_helpers.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • unit_tests/utils/test_datetime_helpers.py
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-the-guardian-api' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.12, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Analyze (python)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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. (Beta)
  • @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.

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: 0

🧹 Nitpick comments (6)
unit_tests/utils/test_datetime_helpers.py (3)

54-68: Consider adding more edge cases to test datetime parsing, wdyt?

The test cases cover basic scenarios well, but we might want to add tests for:

  • Timestamps with different precisions (seconds vs milliseconds)
  • Mixed date separators (e.g., "2023-03/14")
  • Various timezone formats (EDT, PST, etc.)
🧰 Tools
🪛 GitHub Actions: Linters

[warning] File requires formatting. Code does not conform to Ruff's formatting standards.


114-120: Should we remove the commented-out test cases?

These test cases appear to be obsolete with the new permissive parsing approach. Let's keep the codebase clean by removing them, wdyt?

🧰 Tools
🪛 GitHub Actions: Linters

[warning] File requires formatting. Code does not conform to Ruff's formatting standards.


127-133: Consider making the try_parse assertion more explicit, wdyt?

The current assertion combines two conditions. We could make it more explicit and easier to debug:

-        assert ab_datetime_try_parse(input_value) and ab_datetime_try_parse(input_value) == dt
+        parsed = ab_datetime_try_parse(input_value)
+        assert parsed is not None, "Expected successful parsing"
+        assert parsed == dt, "Parsed value doesn't match expected"
🧰 Tools
🪛 GitHub Actions: Linters

[warning] File requires formatting. Code does not conform to Ruff's formatting standards.

airbyte_cdk/utils/datetime_helpers.py (3)

364-372: Would you like to structure the docstring formats more clearly?

Consider using bullet points with examples for each supported format, wdyt?

     Handles:
-        - ISO8601/RFC3339 format strings (with ' ' or 'T' delimiter)
-        - Unix timestamps (as integers or strings)
-        - Date-only strings (YYYY-MM-DD)
-        - Timezone-aware formats (+00:00 for UTC, or ±HH:MM offset)
-        - Anything that can be parsed by `dateutil.parser.parse()`
+        - ISO8601/RFC3339 format strings:
+            - With 'T' delimiter: "2023-03-14T15:09:26Z"
+            - With space delimiter: "2023-03-14 15:09:26Z"
+        - Unix timestamps:
+            - As integer: 1678806566
+            - As string: "1678806566"
+        - Date-only strings: "2023-03-14" (assumes 00:00:00 UTC)
+        - Timezone-aware formats:
+            - UTC: "+00:00" or "Z"
+            - Offset: "±HH:MM"
+        - Any format supported by dateutil.parser.parse()

422-424: Consider strengthening the time-only validation, wdyt?

The current check might have edge cases. Here's a more robust approach:

-        if ":" in dt_str and dt_str.count("-") < 2 and dt_str.count("/") < 2:
+        if (":" in dt_str and 
+            all(sep not in dt_str or dt_str.count(sep) < 2 
+                for sep in ["-", "/", "."])):

This would catch more variations of time-only strings while still allowing valid datetime formats.


Line range hint 464-499: Should we add format string validation?

Consider validating the format string to catch invalid patterns early, wdyt?

     if format:
+        try:
+            # Validate format string with a known datetime
+            datetime.now().strftime(format)
+        except ValueError as e:
+            raise ValueError(f"Invalid format string: {e}")
         return dt.strftime(format)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3af96dc and 4f9e926.

📒 Files selected for processing (2)
  • airbyte_cdk/utils/datetime_helpers.py (8 hunks)
  • unit_tests/utils/test_datetime_helpers.py (3 hunks)
🧰 Additional context used
🪛 GitHub Actions: Linters
unit_tests/utils/test_datetime_helpers.py

[warning] File requires formatting. Code does not conform to Ruff's formatting standards.

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-the-guardian-api' (skip=false)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (All, Python 3.12, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Analyze (python)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: Pytest (Fast)
🔇 Additional comments (1)
airbyte_cdk/utils/datetime_helpers.py (1)

141-147: LGTM! Good forward-thinking with the docstring.

The implementation and documentation clearly explain the current behavior and potential future changes.

@aaronsteers
Copy link
Contributor Author

aaronsteers commented Jan 29, 2025

/autofix

Auto-Fix Job Info

This job attempts to auto-fix any linting or formating issues. If any fixes are made,
those changes will be automatically committed and pushed back to the PR.

Note: This job can only be run by maintainers. On PRs from forks, this command requires
that the PR author has enabled the Allow edits from maintainers option.

PR auto-fix job started... Check job output.

✅ Changes applied successfully.

@aaronsteers aaronsteers merged commit a6d55be into main Jan 30, 2025
23 of 25 checks passed
@aaronsteers aaronsteers deleted the aj/fix/misc-datetime-improvements branch January 30, 2025 17:58
@aaronsteers aaronsteers changed the title fix: make new datetime parse functions properly permissive fix: make new datetime parse functions more permissive Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant