Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-2843] chore: updated the cycle end date logic #6194

Merged
merged 2 commits into from
Dec 13, 2024

Conversation

NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Dec 12, 2024

Description

updated the end date of the cycle to reflect the finish date.

Type of Change

  • Code refactoring

Summary by CodeRabbit

  • New Features

    • Enhanced date conversion logic to support user-specific timezones.
  • Bug Fixes

    • Corrected a syntax error in the CycleUserPropertiesSerializer affecting field definitions.
  • Improvements

    • Updated methods to utilize user timezone for date conversions, improving accuracy in date-related data presented to users.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes in this pull request involve updates to several serializers and views related to cycle management within the application. Key modifications include the introduction of UTC date conversion logic in the CycleSerializer and CycleWriteSerializer, adjustments to how user timezones are handled in the CycleViewSet, and minor corrections in the CycleUserPropertiesSerializer. Additionally, the convert_to_utc function has been modified to reflect changes in parameter handling. Overall, these updates aim to enhance date handling and validation across various components.

Changes

File Path Change Summary
apiserver/plane/api/serializers/cycle.py Added import for convert_to_utc. Modified CycleSerializer.validate to convert start_date and end_date to UTC.
apiserver/plane/app/serializers/cycle.py Updated CycleWriteSerializer.validate to change convert_to_utc call for start_date. Fixed syntax error in CycleUserPropertiesSerializer.
apiserver/plane/app/views/cycle/base.py Updated CycleViewSet to use request.user.user_timezone for date conversions. Adjusted CycleDateCheckEndpoint for convert_to_utc.
apiserver/plane/app/views/workspace/cycle.py Added import for user_timezone_converter, no functional change to WorkspaceCyclesEndpoint.get.
apiserver/plane/utils/timezone_converter.py Modified convert_to_utc function signature and logic for handling is_start_date.

Possibly related PRs

Suggested labels

⚙️backend

Suggested reviewers

  • pablohashescobar
  • sriramveeraghanta

🐇 In the land of cycles, we hop and play,
With dates in UTC, we brighten the day.
From serializers to views, we’ve made it right,
Converting timezones, oh what a delight!
So let’s celebrate with a joyful cheer,
For every cycle, we hold so dear! 🐇✨


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:

  • 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. (Experiment)
  • @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: 2

🧹 Outside diff range and nitpick comments (3)
apiserver/plane/app/serializers/cycle.py (1)

Line range hint 93-93: Fix syntax error in read_only_fields

There's a missing comma between "cycle" and "user" in the read_only_fields list.

-        read_only_fields = ["workspace", "project", "cycle" "user"]
+        read_only_fields = ["workspace", "project", "cycle", "user"]
apiserver/plane/app/views/cycle/base.py (2)

262-262: LGTM! Consider fixing line length.

The change to use user timezone is appropriate. However, the line exceeds the length limit.

-        data = user_timezone_converter(data, datetime_fields, request.user.user_timezone)
+        data = user_timezone_converter(
+            data, datetime_fields, request.user.user_timezone
+        )
🧰 Tools
🪛 Ruff (0.8.2)

262-262: Line too long (89 > 88)

(E501)


460-460: LGTM! Consider fixing line length.

The change to use user timezone is appropriate. However, the line exceeds the length limit.

-        data = user_timezone_converter(data, datetime_fields, request.user.user_timezone)
+        data = user_timezone_converter(
+            data, datetime_fields, request.user.user_timezone
+        )
🧰 Tools
🪛 Ruff (0.8.2)

460-460: Line too long (89 > 88)

(E501)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9ad8b43 and b6a146c.

📒 Files selected for processing (5)
  • apiserver/plane/api/serializers/cycle.py (2 hunks)
  • apiserver/plane/app/serializers/cycle.py (1 hunks)
  • apiserver/plane/app/views/cycle/base.py (3 hunks)
  • apiserver/plane/app/views/workspace/cycle.py (1 hunks)
  • apiserver/plane/utils/timezone_converter.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
apiserver/plane/app/views/cycle/base.py

262-262: Line too long (89 > 88)

(E501)


460-460: Line too long (89 > 88)

(E501)

apiserver/plane/app/views/workspace/cycle.py

13-13: plane.utils.timezone_converter.user_timezone_converter imported but unused

Remove unused import: plane.utils.timezone_converter.user_timezone_converter

(F401)

🔇 Additional comments (3)
apiserver/plane/utils/timezone_converter.py (1)

31-31: Verify the impact of timezone conversion logic change

The change from subtracting a minute from end dates to adding a minute to start dates represents a significant shift in date handling logic. This could affect:

  1. Existing cycles in the database
  2. Integration points that depend on this behavior
  3. Date range calculations in queries

Consider adding a migration plan or documentation for this behavioral change, especially if it affects existing data.

Also applies to: 61-63

✅ Verification successful

Based on the search results, I can now provide a final response:

The timezone conversion change is safely implemented across the codebase

The code search reveals that convert_to_utc is consistently used in cycle-related serializers and views, with proper handling of both start and end dates. The change from is_end_date to is_start_date is consistently applied:

  • In plane/api/serializers/cycle.py and plane/app/serializers/cycle.py, start dates are correctly passed with is_start_date=True
  • End dates are passed without the parameter, defaulting to False
  • All date range queries in views use Django's timezone.now() for comparisons, which is timezone-aware and not affected by this change

The behavioral change from subtracting a minute from end dates to adding a minute to start dates maintains the same effective date ranges, just implemented differently. This change doesn't impact existing data consistency as:

  1. The database stores dates in UTC format
  2. All queries properly use timezone-aware comparisons
  3. The conversion is only applied during serialization/deserialization
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential impacts of the timezone conversion change

# Find all references to convert_to_utc to ensure consistent usage
echo "Checking all references to convert_to_utc:"
rg "convert_to_utc"

# Look for any date range queries that might be affected
echo "Checking date range queries in cycle-related files:"
rg -A 3 "start_date|end_date" --glob "**/*cycle*.py"

Length of output: 12377

apiserver/plane/app/serializers/cycle.py (1)

25-25: Maintain consistency with API serializer implementation

The UTC conversion implementation here should match the error handling improvements suggested for the API serializer.

Also applies to: 28-28

apiserver/plane/app/views/cycle/base.py (1)

536-537: Verify consistent usage of convert_to_utc parameters.

The addition of is_start_date parameter needs to be verified across the codebase to ensure consistent usage.

✅ Verification successful

Let me check the implementation of convert_to_utc function to ensure the parameter is properly handled.


Let me try a different approach to find the function definition using ripgrep.


Let me check the complete implementation of the function to verify the parameter handling.


Let me get the complete implementation as the function seems to continue beyond what we see.


The convert_to_utc parameter usage is consistent across the codebase

Based on the verification:

  • The convert_to_utc function properly implements the is_start_date parameter with a default value of False
  • All start date conversions across the codebase correctly pass is_start_date=True
  • All end date conversions correctly omit the parameter, using the default False value
  • The implementation adds one minute to start dates when is_start_date=True, which is consistently applied
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for all usages of convert_to_utc to ensure consistent parameter usage

# Search for convert_to_utc function calls
ast-grep --pattern 'convert_to_utc($$$)'

Length of output: 1352


Script:

#!/bin/bash
# Search for convert_to_utc function definition
ast-grep --pattern 'def convert_to_utc($$$)'

Length of output: 46


Script:

#!/bin/bash
# Search for convert_to_utc function definition using ripgrep
rg "def convert_to_utc" -A 5

Length of output: 494


Script:

#!/bin/bash
# Get the complete function implementation
rg "def convert_to_utc" -A 20 apiserver/plane/utils/timezone_converter.py

Length of output: 832


Script:

#!/bin/bash
# Get the complete file content to see full implementation
cat apiserver/plane/utils/timezone_converter.py

Length of output: 3492

Comment on lines +28 to +38
if (
data.get("start_date", None) is not None
and data.get("end_date", None) is not None
):
project_id = self.initial_data.get("project_id") or self.instance.project_id
data["start_date"] = convert_to_utc(
str(data.get("start_date").date()), project_id, is_start_date=True
)
data["end_date"] = convert_to_utc(
str(data.get("end_date", None).date()), project_id
)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider additional error handling for date conversion

While the validation logic is sound, consider adding error handling for the convert_to_utc calls which could raise exceptions if:

  1. Project doesn't exist
  2. Invalid timezone in project
  3. Invalid date format
 if (
     data.get("start_date", None) is not None
     and data.get("end_date", None) is not None
 ):
     project_id = self.initial_data.get("project_id") or self.instance.project_id
-    data["start_date"] = convert_to_utc(
-        str(data.get("start_date").date()), project_id, is_start_date=True
-    )
-    data["end_date"] = convert_to_utc(
-        str(data.get("end_date", None).date()), project_id
-    )
+    try:
+        data["start_date"] = convert_to_utc(
+            str(data.get("start_date").date()), project_id, is_start_date=True
+        )
+        data["end_date"] = convert_to_utc(
+            str(data.get("end_date", None).date()), project_id
+        )
+    except (Project.DoesNotExist, ValueError) as e:
+        raise serializers.ValidationError(f"Date conversion failed: {str(e)}")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (
data.get("start_date", None) is not None
and data.get("end_date", None) is not None
):
project_id = self.initial_data.get("project_id") or self.instance.project_id
data["start_date"] = convert_to_utc(
str(data.get("start_date").date()), project_id, is_start_date=True
)
data["end_date"] = convert_to_utc(
str(data.get("end_date", None).date()), project_id
)
if (
data.get("start_date", None) is not None
and data.get("end_date", None) is not None
):
project_id = self.initial_data.get("project_id") or self.instance.project_id
try:
data["start_date"] = convert_to_utc(
str(data.get("start_date").date()), project_id, is_start_date=True
)
data["end_date"] = convert_to_utc(
str(data.get("end_date", None).date()), project_id
)
except (Project.DoesNotExist, ValueError) as e:
raise serializers.ValidationError(f"Date conversion failed: {str(e)}")

@@ -10,7 +10,7 @@
from plane.db.models import Cycle
from plane.app.permissions import WorkspaceViewerPermission
from plane.app.serializers.cycle import CycleSerializer

from plane.utils.timezone_converter import user_timezone_converter
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unused import.

The user_timezone_converter import is not used in this file. Consider removing it until needed.

-from plane.utils.timezone_converter import user_timezone_converter
🧰 Tools
🪛 Ruff (0.8.2)

13-13: plane.utils.timezone_converter.user_timezone_converter imported but unused

Remove unused import: plane.utils.timezone_converter.user_timezone_converter

(F401)

@pushya22 pushya22 changed the title chore: updated the cycle end date logic [WEB-2843] chore: updated the cycle end date logic Dec 13, 2024
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.

3 participants