Skip to content

Commit

Permalink
[WEB-3087] fix: project_id handling in cycle create write serializer (#…
Browse files Browse the repository at this point in the history
…6358)

* chore: handled cycle create write serailizer project_id current instance

* chore: updated instance validation in cycle write serializer
  • Loading branch information
gurusainath authored Jan 9, 2025
1 parent 8c57543 commit 448a34a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion apiserver/plane/app/serializers/cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def validate(self, data):
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
project_id = (
self.initial_data.get("project_id", None)
or (self.instance and self.instance.get("project_id", None))
or self.context.get("project_id", None)
)
is_start_date_end_date_equal = (
True
if str(data.get("start_date")) == str(data.get("end_date"))
Expand Down
14 changes: 7 additions & 7 deletions apiserver/plane/app/views/cycle/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@
# Module imports
from .. import BaseAPIView, BaseViewSet
from plane.bgtasks.webhook_task import model_activity
from plane.utils.timezone_converter import (
convert_utc_to_project_timezone,
convert_to_utc,
user_timezone_converter,
)
from plane.utils.timezone_converter import convert_to_utc, user_timezone_converter


class CycleViewSet(BaseViewSet):
Expand Down Expand Up @@ -270,7 +266,9 @@ def create(self, request, slug, project_id):
request.data.get("start_date", None) is not None
and request.data.get("end_date", None) is not None
):
serializer = CycleWriteSerializer(data=request.data)
serializer = CycleWriteSerializer(
data=request.data, context={"project_id": project_id}
)
if serializer.is_valid():
serializer.save(project_id=project_id, owned_by=request.user)
cycle = (
Expand Down Expand Up @@ -357,7 +355,9 @@ def partial_update(self, request, slug, project_id, pk):
status=status.HTTP_400_BAD_REQUEST,
)

serializer = CycleWriteSerializer(cycle, data=request.data, partial=True)
serializer = CycleWriteSerializer(
cycle, data=request.data, partial=True, context={"project_id": project_id}
)
if serializer.is_valid():
serializer.save()
cycle = queryset.values(
Expand Down

0 comments on commit 448a34a

Please sign in to comment.