Skip to content

fixed the date parsing function#1337

Merged
arkid15r merged 4 commits intoOWASP:mainfrom
abhayymishraa:fix/eventDates
Apr 11, 2025
Merged

fixed the date parsing function#1337
arkid15r merged 4 commits intoOWASP:mainfrom
abhayymishraa:fix/eventDates

Conversation

@abhayymishraa
Copy link
Contributor

Resolves #1322

Add the PR description here.

  • Fixed event dates parsing edgecase

@abhayymishraa abhayymishraa requested a review from arkid15r as a code owner April 10, 2025 18:22
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved event date handling to better interpret complex date inputs, ensuring more consistent scheduling.
  • Tests
    • Added comprehensive tests to validate event date processing, data updates, and category assignments, bolstering overall reliability.

Walkthrough

This pull request refines the date parsing logic in the parse_dates method of the Event class. The implementation now uses rsplit(", ", 1) to isolate the year from the date range instead of splitting on every comma. Additionally, the variable handling the split components has been adjusted to accommodate this change, potentially improving the robustness of date interpretation. The update is complemented by new test cases that validate the functionality of the date parsing and data updating capabilities of the Event model.

Changes

Files Summary of Changes
backend/apps/owasp/models/event.py Updated parse_dates method to use rsplit(", ", 1) for proper splitting of date and year. Renamed month_day_range to parts and modified logic for extracting month and constructing day range.
backend/tests/apps/owasp/models/event_test.py Added multiple test methods to TestEventModel for validating date parsing, updating event data, initializing from a dictionary, and category mapping.

Assessment against linked issues

Objective Addressed Explanation
Fix event date parsing (#1322)

Possibly related PRs

Suggested reviewers

  • kasya

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 45cc6a8 and 9ef4c76.

📒 Files selected for processing (1)
  • backend/tests/apps/owasp/models/event_test.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: CodeQL (python)
  • GitHub Check: CodeQL (javascript-typescript)
🔇 Additional comments (6)
backend/tests/apps/owasp/models/event_test.py (6)

31-76: Well-structured tests with comprehensive coverage for date parsing!

This parametrized test covers a wide range of scenarios including single-day events, date ranges, and edge cases with invalid formats. The test cases are clearly commented, making it easy to understand the purpose of each scenario.


77-91: Good approach testing without mocks

Testing the parse_dates method without mocking ensures the functionality works correctly with real data, providing confidence in the actual integration with the date parser.


92-99: Great test for the specific edge case

This dedicated test for dates with spaces in the range format (e.g., "May 25 - 28, 2025") directly addresses the edge case mentioned in the PR objective. This is crucial to ensure the new date parsing implementation handles these special formats correctly.


100-135: Thorough verification of update_data functionality

The test correctly verifies all expected method calls when updating an existing event, including slugify, parse_dates, and the final save operation. The mock setup is clean and the assertions are comprehensive.


136-167: Comprehensive test for the from_dict method

This test ensures that all properties are correctly set from the input dictionary. It properly mocks dependencies and verifies each property value.


168-193: Well-structured category mapping tests

The parametrized test approach is perfect for this use case, efficiently testing multiple category mappings while keeping the code DRY. Good coverage of both standard categories and the fallback case.

✨ 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 plan to trigger planning for file edits and PR creation.
  • @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.

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

🔭 Outside diff range comments (1)
backend/apps/owasp/models/event.py (1)

104-131: 💡 Verification agent

❓ Verification inconclusive

Add test coverage for the date parsing edge cases.

This function handles various date formats and edge cases, but there are no tests visible in this file. Since you've fixed an edge case related to date parsing (per PR description), adding tests would help ensure this functionality doesn't regress in the future.

Let's check if there are any existing tests for this functionality:


🏁 Script executed:

#!/bin/bash
# Search for tests related to the parse_dates method
rg -l "parse_dates" --glob "*/tests/*"

Length of output: 38


Action Required: Add Test Coverage for Date Parsing Edge Cases

It appears that no tests for the parse_dates functionality were found in the repository (our search for "parse_dates" in the tests folder returned no results). Since this function now handles multiple date formats and edge cases (including the handling of ranges like "May 26-30, 2025"), it's important to add comprehensive test cases. This will safeguard against future regressions.

  • File to Address: backend/apps/owasp/models/event.py (lines 104-131)
  • Key Test Scenarios to Cover:
    • Date ranges with both a start and end day (e.g., "May 26-30, 2025")
    • Cases when the start_date is provided versus not provided
    • Improperly formatted date strings triggering exceptions
    • Edge cases around month boundaries or leap years (if applicable)

Please add tests covering these scenarios in the appropriate test suite to ensure that the date parsing functionality remains robust.

🧹 Nitpick comments (2)
backend/apps/owasp/models/event.py (2)

112-113: Consider adding a separator when joining day parts.

Currently, you're joining the remaining parts with an empty string: "".join(parts[1:]). This could lead to incorrectly formatted day ranges if there are spaces in the original input.

For example, if parts is ["May", "26", "-", "30"], the current code would produce "26-30" as expected. However, if parts is something like ["May", "26", "to", "30"], it would produce "26to30", which is likely not what you want.

Consider using a space separator:

-day_range = "".join(parts[1:])
+day_range = " ".join(parts[1:])

81-81: Consider addressing the existing TODO comment.

There's a TODO to refactor this parsing logic. Now that you've made improvements to the date parsing function, it might be a good time to consider a more comprehensive refactor of the date parsing logic, possibly using more robust date parsing libraries or approaches.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ebad12b and 45cc6a8.

📒 Files selected for processing (1)
  • backend/apps/owasp/models/event.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run frontend unit tests
🔇 Additional comments (1)
backend/apps/owasp/models/event.py (1)

108-109: Good use of rsplit to handle the year extraction more reliably.

Using rsplit(", ", 1) instead of a standard split ensures that only the last comma is used for separating the year from the date part. This handles cases where the date string might contain additional commas (e.g., "May 26-30, San Francisco, 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.

Could you add some tests for Event::parse_dates? It's quite risky to refactor w/o tests.

@sonarqubecloud
Copy link

@abhayymishraa
Copy link
Contributor Author

Done @arkid15r !!

@abhayymishraa abhayymishraa requested a review from arkid15r April 10, 2025 20:03
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.

LGMT

@arkid15r arkid15r added this pull request to the merge queue Apr 11, 2025
Merged via the queue into OWASP:main with commit 96e38fa Apr 11, 2025
22 checks passed
Rajgupta36 pushed a commit to Rajgupta36/Nest-n that referenced this pull request Apr 11, 2025
* fixed the date parsing function

* Added comments

* Added tests for the methods and dateparser
Rajgupta36 pushed a commit to Rajgupta36/Nest-n that referenced this pull request Apr 11, 2025
* fixed the date parsing function

* Added comments

* Added tests for the methods and dateparser
shdwcodr pushed a commit to shdwcodr/Nest that referenced this pull request Jun 5, 2025
* fixed the date parsing function

* Added comments

* Added tests for the methods and dateparser
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.

Fix event date parsing

2 participants

Comments